Enhance your career prospects with our Data Science TrainingKNOW MORE
But none of them tells whether a variable is a Number, string or Boolean. Whatever we assign to the variable, its type becomes that.
A boolean represents only one of two values: true, or false. Think of a boolean as an on/off or a yes/no switch.
var boo1 = true; var boo2 = false;
var num1 = 32; var num2 = +Infinity; console.log(num1); //32 console.log(num2); //Infinity console.log(Number.MAX_VALUE); //1.7976931348623157e+308 console.log(Number.MIN_VALUE); //5e-324 console.log("abc"/2); //NaN
Strings are used for storing text. Strings must be inside of either double(") or single(') quotes. Most recently in ES6 a new quotes was introduced and it’s with tilde(`).
var str1 = 'hello, it is me'; var str2 = "hello, it's me"; var str3 = `hello, it’s me`;
Null has one value: null. It is explicitly nothing. It is useful in JS programming to sometime assign a variable null value.
var nothing = null;
A variable that has no value is undefined. When we first declare a variable as in the statements below, the value of undefined is assigned by the JS compiler.
var testVar; console.log(testVar); // undefined testVar = 3; console.log(testVar); // 3
Symbols are the new primitive data-type introduced in ES6. Symbols are unique an immutable data-type. They are tokens that can be used as unique ids.
Two Symbols are never the same, even if they are declared as same. Consider the below example.
let symbol1 = Symbol(); let symbol2 = Symbol(); console.log(symbol1 === symbol2); //Output - false