undefined- Variable that has been declared but not assigned with a value.
Truthy Values :
Everything else Truthy.
functionisFalsy(value){if(value){console.log ("The value is truthy.");}else{console.log ("The value is falsy.");}}isFalsy(false);//falsy valueisFalsy(0);//falsy valueisFalsy(-0);//falsy valueisFalsy(0n);//falsy valueisFalsy(null);//falsy valueisFalsy(undefined);//falsy valueisFalsy(NaN);//falsy valueisFalsy("");//falsy valueisFalsy('');//falsy valueisFalsy(``);//falsy valueisFalsy(1);//truthy valueisFalsy(-1);//truthy valueisFalsy(0.1);//truthy valueisFalsy(-0.1);//truthy valueisFalsy(1n);//truthy valueisFalsy("false");//truthy valueisFalsy("0");//truthy value isFalsy("null");//truthy valueisFalsy("undefined");//truthy valueisFalsy("NaN");//truthy value
Explicit Type Conversion :
It is used to manually convert a value from one data type to another using build-in functions.
leta="10";letb="10.5";console.log(typeofa);// stringconsole.log(typeofNumber(a));// numberconsole.log(typeofparseInt(a));// numberconsole.log(typeofparseFloat(b));// numberconsole.log(5+"10");// string concatenation, result is "5" + "10" = "510"// If one value is a string, + becomes string concatenation, not addition. Only + behaves differently , others (-, *, /) convert to numbers.// Using unary + we can convert string to numeric.console.log(5++"10");// numeric addition, +"10" converts "10" to 10, result is 5 + 10 = 15console.log(5-"10");// numeric subtraction, "10" is converted to 10, result is 5 - 10 = -5console.log(5*"10");// numeric multiplication, "10" is converted to 10, result is 5 * 10 = 50console.log(5/"10");// numeric division, "10" is converted to 10, result is 5 / 10 = 0.5
Top comments (0)