JS: Tricks – JavaScript meetup: January 2014 – #1



JS: Tricks – JavaScript meetup: January 2014 – #1

0 0


explainJSQuiz

For JS meetup Januar 2014 at chicago

On Github khan4019 / explainJSQuiz

JS: Tricks

JavaScript meetup: January 2014

micro presentation about Kangex JS Quiz

http://bit.ly/1fudaLM

MD Khan / @mdkhan005

#1

(function(){
  return typeof arguments;
})();
							
Array instanceof Object;
//true
							
typeof []; 
//object
							
//arguments are like array
arguments.length;
arguments[3];
arguments[3] = 45;
							
arguments.push(21);
//TypeError: Object has no method 'push'
							

arguments is array like object

typeof arguments;
//"object"
							
(function(){
  return typeof arguments;
})();

//"object"
							

#2

var f =function g(){ return 23; };
typeof g();
						
Answer: GitHub gist: Nigam

#3

(function(x){
  delete x;
  return x;
})(1);
						
Answer: Github gist: Nate

#4

var y = 1, x = y = typeof x;
 x;
							
var x;
x;
//undefined
window.kkkk;
//undefined
							
typeof undefined;
//"undefined"
							
var x; 
typeof x;
//"undefined"
							
var x = typeof x;
x;
//"undefined"
							
var y = 1, x = y = typeof x;
 x;
 //"undefined"
							
js: expression

#5

 (function f(f){
   return typeof f();
 })(function(){ return 1; });
							
function foo(f){
  return f;
}

foo(2);
//2	

foo(myFunc);
//myFunc
fucntion abc(){
  return 1;
}

function foo(f){
  return f();	
}

foo(abc);
//1;
 (function f(f){
   return typeof f();
 })(function(){ return 1; });
 //"number"
							

#6

var foo = {
    bar: function() { 
    	return this.baz; 
    },
    baz: 1
 };
(function(){
  return typeof arguments[0]();
})(foo.bar);
Answer: alternate answer
var foo = {
    bar: function() { 
    	return this.baz; 
    },
    baz: 1
 }; 
							
foo.bar();
//1
							
var kkk = foo.bar;
kkk;
//function(){
//   return this.baz;	
//}
							
kkk();
//undefined
							
var foo = {
    bar: function() { 
    	return this.baz; 
    },
    baz: 1
 };
(function(){
  return typeof arguments[0]();
})(foo.bar);
//"undefined"

#7

 var foo = {
  bar: function(){ return this.baz; },
  baz: 1
}
typeof (f = foo.bar)();
						
Answer: GitHub gist: Dean

#8

var f = (function f(){ return "1"; }, function g(){ return 2; })();
typeof f;
						

#9

var x = 1;
if (function f(){}) {
  x += typeof f;
}
x;
						
Answer: GitHub gist: Jason

#10

var x =[typeof x, typeof y][1];
typeof typeof x;
							
//if not declared 
//or declared not assigned
//things are undefined
typeof y;
//"undefined"
							
[typeof x, typeof y][1];
//"undefined"
var x =[typeof x, typeof y][1];
x;
//"undefined"
							
typeof "undefined";
//"string"
typeof "string";
//"string"
var x =[typeof x, typeof y][1];
typeof typeof x;
//"string"
							

#11

(function(foo){
  return typeof foo.bar;
})({ foo: { bar: 1 } });
							
var foo = {
	foo: {
      bar: 1
    }
}
foo.foo.bar;
//1
foo.bar;
//undefined
function abc(foo){
   return foo.bar;
}
abc();
//undefined
typeof undefined;
//"undefined"
(function(foo){
  return typeof foo.bar;
})({ foo: { bar: 1 } });
//"undefined"
							

#12

(function f(){
  function f(){ return 1; }
  return f();
  function f(){ return 2; }
})();
						
Answer: GitHub gist: Steve

#13

function f(){ return f; }
new f() instanceof f;
						

#14

with (function(x, undefined){}) length;
						

Thank You

http://bit.ly/1fudaLM

MD Khan / @mdkhan005