Javascript Deck 4 Flashcards
Single Responsibility Principle (SRP)
Each function or class should only have one responsibility
Open/Closed Principle(OCP)
Software entities should be open for extension but closed for modification
Liskov Substitution Principle(LSP)
Subtypes must be substitutable for their base types without altering the correctness of the program
Interface Segregation Principle(ISP)
Clients should not be forced to depend on interfaces they do not use
Dependency Inversion Principle(DIP)
High-level modules should not depend on low-level modules. Both should depend on abstractions
TL;DR
Follow SOLID principles to write clean, maintainable, and extensible javascript code
Fetch Method
The fetch() method in JS is used to request to the server and load the information in the webpages. The request can be pf any API’s that return the data of the format JSON or XML. This method returns a promise
For Loop
Syntax
for(initialExpression; condition; updateExpression){}
ex:
const numbers = [1,2,3];
for(let i = 0; i < numbers.length; i++){
console.log(numbers[i]);
}
//prints - 1
2
3
Do-While Loop
Syntax
do{
//body of loop
while(condition)
}
ex:
const numbers = [1,2,3];
do{
console.log(numbers[i]);
i++;
while(i < numbers.length)
}
//prints - 1
2
3
While Loop
Syntax
while(condition){
//body of loop
}
ex:
const numbers = [1,2,3];
let i = 0;
while(i < number.length){
console.log(numbers[i]);
i++;
}
//prints - 1
2
3
For Each
Syntax
array.forEach(function(currentValue), index, arr);
ex:
[1,2,3].forEach((elem) => => {
console.log(elem);
})
prints - 1 2 3
Map
Syntax
array.map(function(currentValue, index, arr), callback function)
const results = [1,2,3].map((elem) => {
return elem.toFixed();
})
For of loop —ARRAY/ITERABLE
Syntax
for(element of iterable){
//body of for… of
}
const numbers = [1,2,3];
for(let ele of cars) {
console.log(ele);
}
prints 1 2 3
For In Loop — Object
Syntax
for(key in object){
//body of the for… in
}
const data = {id:1, name:’Joe’, age:’45’}
for(let key in data){
console.log(data[key])
}
//prints 1 Joe Age
Center Div – FLEX
.parent{
display:flex;
justify-content:center;
align-items:center;
}