Null vs Undefined
Global Variable & Scope
and code that is not written inside any function is globally scoped, let’s say you have a variable in your code which is not defined inside any function is globally scoped that’s mean, you can use that variable anywhere from your code.
Loose equality vs Strict equality (== vs ===)
console.log(3 == "3") // true
here it's logging true because we are using loose equality operator which checks only value not the type that whether the two same or different type like here one is number type and another value is string typeconsole.log(3 === "3") false
here it's logging false because we are using strict equality operator which not only checks that is the values of both same but also checks the type, here one is number type and another is string type that's why logging false in console
Truthy vs Falsy
"", '', `` (empty string)
There are the value that coerces to falsy if passed in place of Boolean and what are the values that coerces to truthy? It’s simple, what is not falsy is truthy.
Addition Operator (+)
var sum = "3" * 3 // 9
instead of doing math operation, giving the result 6 it's giving 33 because it's concatenating
So next time when you need to do math operations make sure you are doing with real numbers or explicitly coerce it to number with Number() method.
var sum = 3 * 'car'