variable
before ES6 we use the var keyword.
let name = 'Amy';
console.log(name);
//varable name cannot be a reserved key word
//should be meaningful
//cannot start with a number(1name)
//cannot contain a space or hyphen(-)
//are case-sensitive
let firstName;
let lastName;
constant
const interestRate = 0.3;
primitive/value types: String, Number, Boolean, undefined, null
reference types: Object, Array, Function
typeof name
Dynamic typing
Objects
curly braces
let person = {
name: 'Nosh',
age: 30
};
//Dot notation
person.name = 'james';
//bracket notation
person['name']='mary';
Array
let selectedColors = ['red', 'blue'];
selectedColors[2] = 'green';
console.log(selectedColors[0]);
Tycinically, array is object too.
Functions
function greet(){
condole.log('hello word');
}
greet();
function greet(name){
console.log('hello'+name);
}
greet('John');
//calculating a value
function square(number){
return number * number;
}
let number = sqaure(2);
console.log(number);