Truthy and Falsy values in javascript :
In javascript falsy values are defined as :
- when the condition is false 2.when value = 0
- empty string is also a falsy value
- Null is a falsy value
- Undefined is also falsy
- NaN is also falsy
In javascript truthy values are defined as:
- When the condition is true
- Any numbers (negative or positive)
- Any string including single white space 4.[] an empty array
- {} an empty object
-
anything that is not falsy will be truthy
**Null vs undefined**
undefined
:
It means a variable is declared, but no value has been assigned a value.
For example,
var demo;
alert(demo); //shows undefined
alert(typeof demo); //shows undefined
null :
Whereas, null in JavaScript is an assignment value. You can assign it to a variable.
For example,
var demo = null;
alert(demo); //shows null
alert(typeof demo); //shows object
double equal (==) vs triple equal (===) in javascript
== in JavaScript is used for comparing two variables, but it ignores the datatype of the variable. === is used for comparing two variables, but this operator also checks datatype and compares two values.
Oldest comments (0)