Farhan Eshrak
2 min readMay 8, 2021

--

Truthy and Falsy values
//Checking truthy and falsy value

function truthyOrFalsy (val) {
if(val) {
return true
} else {
return false
}
}

console.log(truthyOrFalsy(0)) // print false
console.log(truthyOrFalsy(5)) // print true

Null Vs Undefined
Null as an assignment value. So you can assign the value null to any variable which basically means it’s blank.
Undefined is a variable that has been declared but not assigned a value.

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

var num = 0;
var obj = new String(‘0’);
var str = ‘0’;

console.log(num === num); // true
console.log(obj === obj); // true
console.log(str === str); // true

console.log(num === obj); // false
console.log(num === str); // false
console.log(obj === str); // false
console.log(null === undefined); // false
console.log(obj === null); // false
console.log(obj === undefined); // false

Global Scope
There’s only one Global scope in the JavaScript document. The area outside all the functions is consider the global scope and the variables defined inside the global scope can be accessed and altered in any other scopes.
Local Scope
Variables declared inside the functions become Local to the function and are considered in the corresponding local scope. Every Functions has its own scope. Same variable can be used in different functions because they are bound to the respective functions and are not mutual visible.
//global scope
Function Scope
Whenever you declare a variable in a function, the variable is visible only within the function. You can’t access it outside the function. var is the keyword to define variable for a function-scope accessibility.
Block Scope
A block scope is the area within if, switch conditions or for and while loops. Generally speaking, whenever you see {curly brackets}, it is a block. In ES6, const and let keywords allow developers to declare variables in the block scope, which means those variables exist only within the corresponding block.

--

--