10 JavaScript Topics Every Developer need to know
Null vs Undefined
Undefined: Undefined means that, a variable is declared but not assigned any value.
Null: It’s an assignment value. It can be assigned to a variable as a representation of no value.
Null and undefined are equal in value but different in type.
null == undefined // true
null === undefined // false
Truthy and Falsy values
All values are truthy unless they are defined as falsy.
Truthy values: true, {}, [], 112, '0', "false", new Date(), -92, 12n, 3.1416, -3.1416, Infinity, -Infinity
Falsy values: false, null, undefined, NaN, 0, -0, 0n, '', ""(Empty string)
Double Equal(==) vs Triple Equal(===)
Double Equal only check the values but Triple Equal check the values and data type.
10 == '10' // true
10 === '10' // false
Implicit Conversion vs Explicit Conversion
When JS automatically converts a data type of a variable, then it’s called Implicit conversion. Also, we can convert data types manually. It’s called Explicit Conversion.
console.log(10 + 5); // output: 15console.log('10' + 5); // output: 105
In addition operation, it converted into string and concate two strings. Because, in JS we can concate string with +(plus) sign.console.log('10' - 5); // output: 5
In subtraction, it converted into number and perform the mathmetical operation.console.log('10' * 5); // output: 50
console.log('10' / 5); // output: 2
if need to convert manually:
const x = '112';
console.log(typeof(x)); // string
console.log(typeof(parseInt(x))); // number
or,
const y = parseInt(x);
console.log(typeof(y)); // numberconst m = 112;
console.log(typeof(m)); // number
console.log(typeof(m.toString())); // string
or,
const n = m.toString();
console.log(typeof(n)) // string