10 Javascript Job Interview Question You Should Know.
What Is the Truthy And Falsy Values ?
In Javascript , as a condition two ways values condition rendering. which is truthy and falsy values.
Truthy value
In Javascript , a truthy value is a value that is considered true when encountered in a boolean context. Anything variable value define what’s mentioned above is truthy. Simply any variable with a value is truthy.
Below are some truthy values.
true - boolean true context.
{} - An object (whether empty or not)
[] - An array (whether empty or not)
10 - (whether positive or negative)
'true' - Non empty strings
'false' - Non empty strings
new Date() - Date object
Falsy Value
Falsy value simple term in javascript when we are variable define if value do not have values and dot exit , that is code block return false value.
Below are some Falsy values.
false - boolean false context.
0 - Negative falsy Values
"" - Empty String
null - returns no value
undefined - returns no values
nan - value return nan
Null VS Undefined What is the difference Between.
Null and Undefined
Both ar represent “ No Values ”.
Undefined
Undefined — Javascript can not find value for this
Undefined — Variable define without value
Undefined — Missing Function Arguments
Undefined — Missing object Properties
Null
Null — Developers sets the value.
Below some example :
What Is The Difference Between Double Equal( == ) VS Triple Equal ( === )
Double Equal( == )
When Using double equal In Javascript this are lose equality type checking.Double equals also performs type coercion
Type coercion means that two values are compared only after attempting to convert them into a common type.
Double equal also comparison just type value checking . double Equal Not Concern type checking. double equal not strict as type value checking.
Triple Equal ( === )
When using triple equal ( === ) we are in javascript type and value checking must be true , rather then throw in error. so triple equal is very strict, concern , type and value checking.
Triple equal expect both the type and the value we are comparing have to be the same.