Basics Flashcards
What is coercision
Process of converting a variable to string for representational purpose
“99.99” == 99.99
True, the RHS is converted to string
What typing is used in JS
Dynamic typing
How to take only two values from a number
number.toFixed(2)
function outer() { var a = 1;
function inner() { var b = 2; console.log( a + b ); }
inner(); console.log( a ); }
outer();
Output of this problem
3
1
a = null;
typeof a;
what is the output
object
Declare array
var arr = [1,2,3];
what non boolean values when coerced to bool will give false value
0 -0 "" nan null undefined false
== checks for
Value equality, while allowing for coercion
=== checks
Value and type equality
obj a = { a:10}
obj b = {a:9}
a ==b
a===b
The checks are done only for reference equals and checking the underlying values
var a = [1,2,3]; var b = [1,2,3]; var c = "1,2,3";
a == c;
b == c;
a == b;
true
true
false
Arrays are coerced into string by default separated by commas
Scope of b and c and why?
function foo() { var a = 1;
if (a >= 1) { let b = 2;
while (b < 5) { let c = b * 2; b++;
console.log( a + c ); } } }
foo();
b will belong only to the if statement and thus not to the whole foo() function’s scope. Similarly, c belongs only to the while loop
Immediately Invoked Function Expressions (IIFEs) example
(function(){
return 10;
})();
Closure
Having one function inside other and the concept is the child function remebers the variable in scope for the parent function even after the parenr function has returned