var x1 = 34.00; // Written with decimals var x2 = 34; // Written without decimals var y = 123e5; // 12300000 var z = 123e-5; // 0.00123
var carName = "Volvo XC60"; // Using double quotes var carName = 'Volvo XC60'; // Using single quotes var answer = "It's alright"; // Single quote inside double quotes var answer = "He is called 'Johnny'"; // Single quotes inside double quotes var answer = 'He is called "Johnny"'; // Double quotes inside single quotes
var x = true; var y = false;
0 == false // Is true 1 == true // Is true !0 // Is true 0 // Is false 1 // Is true -1 // Is true (any number other than 0 is true)
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
var cars = ["Saab", "Volvo", "BMW"];
typeof "John" // Returns "string" typeof 3.14 // Returns "number" typeof false // Returns "boolean" typeof [1,2,3,4] // Returns "object" (not "array", see note below) typeof {name:'John', age:34} // Returns "object"
var person; // Value is undefined, type is undefined
var person = null; // Value is null, but type is still an object
var person = undefined; // Value is undefined, type is undefined
typeof undefined // undefined typeof null // object null === undefined // false null == undefined // true
* Examples and content from W3Schools.com.