...
- spread or compress
callback
- passing in a function
.forEach(function)
- element, index, array, goes through all elements
.map(function)
- applies a function and returns a new array
filter(function)
- takes values that are true, and places them in a new array
.reduce(function)
- reduces all elements of an array to a single value; accumulator (current
element), element (next element)
.toFixed(number)
- fixed decimal points
funtion declaration
- defines a reusable block of code that performs a specific task
function expression
- way to define functions as values or variables
const hello = function(){
body
}
hello();
setTimeout(function(){
[Link]("Hello")
}, 3000);
Used when function is only used once
Arrow functions
- (parameters) => some code
- when only using once
const hello = () => [Link]("Hello")
hello()
const funcName = (parameters) => code;
funcname();
setTimeout( () => [Link]("Hello"), 3000);
OOP
Object
- collection of related properties and or methods
object = {key:value,
function()}
const person ={
firstName: "Daniel",
lastName: "Fernando",
sayHello: function() {[Link]("Hi")},
}
[Link]([Link]);
[Link]();
this. is the reference for the object in
Constructor
- Special method for defining the properties and methods of objects
function Car(make,model,year,color){
[Link] = make,
[Link] = model,
[Link] = year,
[Link] = color,
}
const car1 = new Car ("Ford", "Mustang", 2024, "red");
Class
- provides a more structured and cleaner way to work with objects
class Product{
constructor(name, price){
[Link] = name,
[Link] = price,
}
displayProduct(){
body
}
}
const product1 = new Product("Shirt", 19.99);
Static
- Same thing para sa lahat
class MathUtil{
static Pi = 3.14159;
}
[Link]([Link]);
Inheritance
- A child inherits the properties of a child
class Animal{
}
class Rabbit extends Animal{
}
Super
- calls the constructor of the parent,
- Call the super() before using constructors in child classes
[Link]();
Getters and Setters
Getter = makes a property readable
setter = makes a property writeable
- validates and modifies a value when reading/writing a property
set width(newWidth){
if(newWidth>0){
this._width = newWidth;
}
}
get width(){
return this._width;
}
Destructuring
- extracts values from array and objects, then assign to values
- [] for arrays
- {} for objects
[1,2] = [2,1]
const [element1, element2] = array
const {element1, element2 = default value} = object
you can also pass it in functions