Tricky Javascripts
Undefined & Null
undefined :
undefined typically means a variable has been declared but no value has been assigned a value
let demo;
alert(demo); //shows undefined
alert(typeof demo); //shows undefined
null :
null is an assigned value. It means nothing. You can assign it to a variable.
let demo = null;
alert(demo); //shows null
alert(typeof demo); //shows object
What is the difference between == and === in JavaScript?
Double equals (==) is an abstract equality comparison operator, which transforms the operands to the same type before making the comparison.
simply , Double Equals ( == ) checks for value equality only.
For example,
- 4 == 4 // true
- ‘4’ == 4 //true
- 4 == ‘4’ // true
- 0 == false // true
Triple equals (===) are strict equality comparison operator, which returns false for different types and different content.
simply,triple Equals ( === ) checks for value and data type equality,
For example,
- 4 === 4 // true
- 4 === ‘4’ // false
- let v1 = {‘value’:’key’};
- let v2 = {‘value’: ‘key’};
- v1 === v2 //false
Arrow Functions!
Though we have shown an example about arrow functions in the last example, let’s talk about it now. Usually, while declaring a function, you had to name it first and get a return type you had to specify. But arrow functions help you to work more easily with fewer codes.
Block Scope
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.
JSON
JSON is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute-value pairs and arrays. It is a very common data format, with a diverse range of applications, one example being web applications that communicate with a server.
JSON Syntax Rules
JSON syntax is derived from JavaScript object notation syntax:
- Data is in name/value pairs
- Data is separated by commas
- Curly braces hold objects
- Square brackets hold arrays