Speaking JavaScript Flashcards
Rauschmayer
What is the effect of this instruction?
myFunction(y>=0 ? y: -y){ return y}
What about this one:
f = myFunction(y>0 ? y: -y);
In the first case, you will get an error (Unexpected token >=) because functions do not accept conditional statements as parameters;
In the second case, that is a function statement so it can take a conditional expression as a call argument;
What is the effect of reading an unknown property?
A value of unknown property is undefined
What is the value of a missing parameter?
Undefined
What is the value of uninitialised variables?
Undefined
What is the logical value of undefined and null?
Both are false
What is the meaning of null?
It means “no object”. It is used where an object is expected
What is the difference between typeof and instanceof?
typeof( ) is meant to be used with primitive values, whereas instanceof( ) is meant to be used with objects
What is the value of: typeof(null)
It is ‘object’»_space;> this is a Quirk
What is the logical value of an Object?
Objects are considered as “true”
What is the effect of: false && foo()
foo is never called
What is the effect of : true || foo( )
foo is never called
What is the logical value of: Infinity > NaN
false, because Infinity is bigger than any other number (except NaN)
What is the effect of:
let s = “abc”;
s.len++;
console.log(s.len);
undefined.
How do you enforce a function parity?
By checking the argument.length
How do you convert arguments to an array?
Array.prototype.slice.call(myArguments);
Can you remove elements from arguments?
No, because arguments is not an array
What is “this” pointing to in an object’s method?
It’s pointing to the actual object
What is the value of “this” inside a forEach method of an object’s property?
It is pointing to the global scope: var jane = { name: 'jane', friends: 'Tarzan', 'Cheetah', yell: function( ) { this.friends.forEach(function(friend){ console.log(this.name); // this point to global scope }) } }
What is “this” bound to in an object’s method? When is binding of “this” happening?
It is bound to that object (Crockford 1). The binding happens at invocation time.
How do the object’s public methods get their context?
They get their context from the invocation of “this” in an object