JS.notes
JS.notes
Basics: [1, 2]
• Variables: Declared using let or const, followed by variable name and assignment with = operator. [1, 2]
• Comments: [3]
Operators: [1, 2]
• Arithmetic: +, -, *, /, %
Control Flow:
if-else statement.
if (condition) {
} else {
3
// code to execute if condition is false
switch-case statement.
switch (expression) {
case value1:
break;
case value2:
break;
default:
// code if no match
• Loops:
• for loop:
// code to execute
while loop.
while (condition) {
// code to execute
do-while loop.
do {
6
// code to execute
} while (condition);
Functions:
Function declaration.
Function invocation.
Arrays:
Creating an array.
Accessing elements.
• Array methods: push, pop, shift, unshift, splice, slice, forEach, map, filter, reduce [1, 2]
Objects:
Creating an object.
Accessing properties.
• Selecting elements:
• document.getElementById('elementId')
• document.querySelector('.className')
• document.querySelectorAll('tagName')
• Modifying elements:
9
• element.textContent = 'New Text'
• element.style.color = 'red'
• Closures: Functions that can access variables from their outer scope
• Async:
Each time when an async function is called, it returns a new Promise which will be
• Await:
The resolved value of the promise is treated as the return value of the await expression.
Use of async and await enables the use of ordinary try / catch blocks around asynchronous code.
• Closures: Functions that can access variables from their outer scope