Frontend Flashcards
Promise
- promise object represents completing or failure of an async operation
- a promise is a proxy for value that is not essentially known when promise is created
- with promise , async methods can return value like sync methods
- instead of returning an instant value , method will return a promise which will be possible a value in future
- promsie state : pending , fullfilled , failure
Using promise
- promiseMethod.then(successFunc , failureFunc)
- chaining promise vs callback hell
- if first promise returns another promise we can use it to chain promises (eventual tasks after another)
Promise api
- promise.all() : takes promises as input and return a single promise
-promise.any() : same as above , if any resolved final promise will be resolved - promise.race() : same as above , first promise is final promise
- Promise.reject() : Returns a new Promise object
async/await
- special syntax to work with promises
- easy and clean
- async and await keywords
- error handling with try catch blocks
- using await to make function pause and behave async
virtual dom
- Document object model
- tree shape object with branches
- with dom , js can make html dynamic
- virtual dom is a lightweight javascript representation of Real Dom
- libraries such as ReactDom sync virtual dom to Real dom
git
- a distributed control version system
- ## famous workflows : truck based and gitflow
js data types
- built-in data structures
- js is dynamic type means variables are not directly associated with any particular value type , in result any variable can be assigned or reassigned by any value type
- weakly typed : allows implicit type conversion where an operation involves mismatch types
- in js all types expect object define immutable values represented directly at the lowest level of language
- all primitive can be tested by typeof expect null and undefined
- Null , undefined, string , number ,symbol , bigint , boolean
- Object , (dates , indexed collection like array , keyed collection liker map , set and structured data like json)
typescript type and interface
- typescript is a seperset of javascript and a seprate langugage
- it adds type checking and ide completation
- we can define types based on built-in types with interface and type keywords
- basic types in ts (same as js just more) are : boolean , string ,number, array , tuple , Enum , Uknown , any , void,null and undefined , never , object
closure
- a form of lexical scoping that used to preserve variables from outer scope of a function in the inner scope of function
- usage : closures let you associate data (the lexical env) with a function that operates on that data , it is a paradigm like object oriented programming , where object lets you associate data (object props) with one or more methods
hoisting
a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution
- var and function declarions
- let , const , use strict
scope
- current context of execution in which values and expressions are “visible” or can be referenced
- Scopes can also be layered in a hierarchy
-child scopes have access to parent scopes, but not vice versa
-
Global scope
The default scope for all code running in script mode.
Module scope:
The scope for code running in module mode.
Function scope
The scope created with a function.
Block scope
The scope created with a pair of curly braces (a block).
What is Cross-Site Scripting (XSS)
XSS, Cross-Site Scripting is an attack which takes place when any attacker uses a web application to send any malicious code, in the form of browser side script, to another user.
What is callback hell?
The callbacks which are stacked in the form of pyramid structure.
when we use callback functions to do async operations , chaining of callback function make code very messy and hard to read
Polymorphism
The word Polymorphism means having many different forms. If we talk in object-oriented form, polymorphism refers to one interface, multiple functions.
Strict Mode?
A new feature of ECMAScript 5 is Strict mode which lets you place a function, or a program in a “strict” context of operating.
What is meant by the KISS principle?
KISS, a backronym of “Keep it simple, stupid”. Which was the principal design in the US Navy in 1960. The KISS principle states that the simpler the system the better it works.
What does SOLID stand for?
S- single responsibility principle
O- open-closed principle
L- Liskov Substitution principle
I- interface segregation principle
D- dependency.
What is type Coercion in JavaScript?
The conversion of two different build-in Types of JavaScript is called Coercion. It comes in two forms, Explicit and implicit.
Mention ways to decrease page load time?
Image optimization
Browser cache
Compress and optimize content
State the elements of the CSS Box Model.
Content
Padding
Border
Margin