Notes
Numbers:
JavaScript has only one type of numbers and can be written with or without decimals.
var x = 12;
document.write(x);
Output: 12
var y = 3.14;
document.write(y);
Output: 3.14
var y = 3.14;
document.write(typeof(y));
Output: number
Strings:
A string is a series of characters like "Will Smith".
Strings are written with single or double quotes.
document.write("Will Smith");
Output: Will Smith
document.write('Will Smith');
Output: Will Smith
let x = 'Will Smith';
document.write(typeof(x));
Output: string
Booleans:
Booleans can only have two values as true
or false
and often used in conditional testing.
let x = 12;
let y = 15;
document.write(x==y);
Output: false
let x = 12;
let y = 15;
document.write(typeof(x==y));
Output: boolean
JS Arrays:
JavaScript arrays are written with square brackets and separated with commas.
const primes = [2, 3, 5, 7];
primes is the name of the array. 2, 3, 5 and 7 are the items of the array.
Every item has an array index. Array indexes are zero-based, which means the first item is [0], second is [1], and so on.
JS Objects:
JavaScript objects are written with curly braces {}.
const user = {userName:"John", password:"12abA", role:"Admin"};
In the example above, username is the name and John is the value.
Undefined:
In JavaScript, a variable without a value, has the value undefined. The type is also undefined.
let x = undefined;
document.write(x);
Output: undefined
let x = undefined;
document.write(typeof(x));
Empty Elements:
let txt = "";
document.write(txt);
Output: