JavaScript
Variables and Constants
functionScoped = 2
blockScope = 5
constant1 = -3
Variable Types
numberVariable=123; floatingPointNumber = 234.345
stringVariable = Hello World!
booleanVariable = true
isNumber = number
isString = string
isBoolean = boolean
Boolean Variables
true1 = true
false1 = false
false2 = false
true2 = true
true3 = true
true4 = true
true5 = true
false3 = false
Functions
Legacy ES5 functions
twoPlusFour = 6
add(2, 4)= 6
New ES6 arrow functions
threeMinusOne = 2
subtract(3, 1) = 2
Implied Return
fourTimesFive = 20
multiply(4, 5) =20
Parenthesis and parameters
twoSquared = 4
square(2) = 4
threePlusOne = 4
plusOne(3) = 4
Working with Arrays
numberArray1 = 12345
stringArray1 = string1string2
variableArray1 = 25-312345string1string2
Array Index and Length
length1 = 5
index1 = 2
Add and Remove Data to Arrays
numberArray1 = 12456
stringArray1 = string1string3
Looping through arrays
stringArray2 = STRING1STRING3
Map
squares = 149162536
cubes = 182764125216
JSON Stringify
squares = [1,4,16,25,36]
Find Function
fourIndex = 4
string3Index = string3
FindIndex Function
fourIndex = 2
string3Index = 1
Filter Function
numbersGreaterThan2 = 456
evenNumbers = 246
oddNumbers = 15
Template Literals
result1 = 2 + 3 = 5
result2 = 2 + 4 = 5
greeting1 = Welcome home alice
greeting2 = Logged in : No
House
bedrooms
4
bathrooms
2.5
Data
{
"bedrooms": 4,
"bathrooms": 2.5,
"squareFeet": 2000,
"address": {
"street": "Via Roma",
"city": "Roma",
"state": "RM",
"zip": "00100",
"country": "Italy"
},
"owners": [
"Alice",
"Bob"
]
}
Spread Operator
Array Spread
arr1 = [1,2,3]
arr2 = [1,2,3,4,5,6]
Object Spread
{"a":1,"b":2,"c":3}
{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6}
{"a":1,"b":4,"c":3}
Destructing
Object Destructing
const { name, age } = { name: "John" age:25 salary:1000000 }
name = John
age = 25
salary = 1000000
Array Destructing
const [first, second, third] = ["one", "two", "three"]
first = one
second = two
third = three
four = 4
Function Destructing
const add = (a, b) => a + b;
const sum = add(1, 2);
const subtract = ({ a, b }) => a - b;
const difference = subtract({ a: 4, b: 2 });
sum = 3
difference = 2