Basics Flashcards

1
Q

What is coercision

A

Process of converting a variable to string for representational purpose

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

“99.99” == 99.99

A

True, the RHS is converted to string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What typing is used in JS

A

Dynamic typing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to take only two values from a number

A

number.toFixed(2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
function outer() {
	var a = 1;
	function inner() {
		var b = 2;
        	console.log( a + b );
	}
inner();

console.log( a ); }

outer();
Output of this problem

A

3

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

a = null;
typeof a;

what is the output

A

object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Declare array

A

var arr = [1,2,3];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what non boolean values when coerced to bool will give false value

A
0
-0
""
nan
null
undefined
false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

== checks for

A

Value equality, while allowing for coercion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

=== checks

A

Value and type equality

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

obj a = { a:10}
obj b = {a:9}

a ==b
a===b

A

The checks are done only for reference equals and checking the underlying values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
var a = [1,2,3];
var b = [1,2,3];
var c = "1,2,3";

a == c;
b == c;
a == b;

A

true
true
false

Arrays are coerced into string by default separated by commas

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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();

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Immediately Invoked Function Expressions (IIFEs) example

A

(function(){
return 10;
})();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Closure

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the output

function foo() {
	console.log( this.bar );
}

var bar = “global”;

var obj1 = {
	bar: "obj1",
	foo: foo
};
var obj2 = {
	bar: "obj2"
};

// ——–

foo();
obj1.foo();
foo.call( obj2 );
new foo();

A

“global”
“obj1”
“obj2”
“Undefined” //because new creates a brand new this object

17
Q

What does Object.Create() do ?

A

The Object.create() method creates a new object, using an existing object as the prototype of the newly created object

18
Q
What is teh output ?
x = 10
console.log(x !== x)
x = NaN
console.log(x !== x)
A

True
False

NaN the only value in the whole language that is not equal to itself.

19
Q

What is Polyfilling?

A

Providing stubs for methods which are not present in the current version of JS

20
Q

What is Transpiling?

A

Converting Newer JS syntax into a form the browser understands

21
Q

How to get all objects passed to a function call ?

A

Every function has the “arguments” object, which can be indexed to get the values passed to it

22
Q

Names of some Transpilers?

A

Babel and Traceur

23
Q

document object,
console.log()
alert()what are they?

A

They are not provided by the JS engine, nor is it particularly controlled by the JavaScript specification.
They may be implemented in other languages and given to us by the browsers to use from JS code

24
Q

how does anonymous function call itself to perform recursion

A

It can use “arguments.callee”, but it is deprcated