DEV Community

loading...

JavaScript Interview

jewellahmed profile image jewellahmed ・1 min read

Truthy & Falsy Values:

In JavaScript, different values equate to true when compared with == (loose or abstract equality) because JavaScript (effectively) converts each to a string representation before comparison.Ex:
// all true
1 == '1';
1 == [1];
'1' == [1];

A more obvious false result occurs when comparing with === (strict equality) because the type is considered.Ex:
// all false
1 === '1';
1 === [1];
'1' === [1];

Null Vs Undefined, different ways to get undefined:

Undefined means a variable declared, but no value has been assigned a value.Ex:
var numb;
alert(numb); //shows undefined
alert(typeof numb); //shows undefined

Null in JavaScript is an assignment value. One can assign it to a variable.Ex:
var name = null;
alert(name); //shows null
alert(typeof name); //shows object

double equal (==) vs triple equal (===), implicit conversion:

In JavaScript, different values equate to true when compared with == (loose or abstract equality) because JavaScript (effectively) converts each to a string representation before comparison.Ex:
// all true
1 == '1';
1 == [1];
'1' == [1];

A more obvious false result occurs when comparing with === (strict equality) because the type is considered.Ex:
// all false
1 === '1';
1 === [1];
'1' === [1];

Scope, Block Scope:

Scope determines the visibility or accessibility of a variable or other resource in the area of one's code.

A block scope is the area within if, switch conditions or for and while loops. {} brackets covered area are considered as block scope.Const and let keywords allow developers to declare variables in the block scope.

Discussion (0)

Forem Open with the Forem app