JS Scrimba

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

JSON=>key and value pair,message are passed from server to browser

Local storage=>contain key and value pair


localstorage.clear();
localstorage.setItems(“myLeads”,”www.google.com”)
// 1. Save a key-value pair in localStorage
localStorage.setItem("lead","www.google.com")
console.log(localStorage.getItem("lead"))
localStorage.clear()
console.log(localStorage.getItem("lead"))
// 2. Refresh the page. Get the value and log it to the console
// 3. Clear localStorage

// HINTS:
// localStorage.setItem(key, value)
// localStorage.getItem(key)
// localStorage.clear()
// PS: both key and value need to be strings

JSON.Parse()=>string to array
JSON.stringify()=>object,array to string

Falsy values=>false,null(developer emphasise the null value),” ”,undefined(javascript emphasise the


null value),0,NaN
// 0
// ""
// null -> how you as a developer signalize emptiness
// undefined -> how JavaScript signalizes emptiness
// NaN

Refactoring JavaScript Refactoring means updating the source code without changing
the behaviour of the application

String literals=>it uses back ticks(` `) and access the value of the variable using string
interpolation(${var1..})
Example:let text = `Welcome ${firstName}, ${lastName}!`;

Destructuring Object:unpack the values from the array and store it in the distinct variable
Example:
const obj = { a: 1, b: 2 };
const { a, b } = obj;
// is equivalent to:
// const a = obj.a;
// const b = obj.b;

Destructuring Array
Example:let [num1,num2,num3] = [1,2,3]
//num1=1
//num2=2
//num3=3

Spread Operator=>to make a exact copy of the object or array(...variablename)


Example:
const numbersOne = [1, 2, 3];
const numbersTwo = [4, 5, 6];
const numbersCombined = [...numbersOne, ...numbersTwo];
console.log(numbersCombined)
o/p=[1,2,3,4,5,6]

Rest Operator=> return rest of the specified value in a array which is declared in parameter
Example:
Function fn(...nums){
return nums
}
o/p=[1,2,3,4,5,6]
fn(1,2,3,4,5,6)
Functions
NORMAL FUNCTION
function fun(){
return “hii”
}
fun()//calling
ANONYMOUS FUNCTION
const f = function(){
return “hiii”
}
f()..calling
ARROW FUNCTION
const f = () => “hii”
f()//calling

JS HOISTING=> a variable can be used before its declaration


EXAMPLE;
x=5
console.log(x)//5
var x

IMPORT AND EXPORT


eg:export var a=5
import {a} from ‘index.js’
Named Exports

● Can export multiple values


● MUST use the exported name when importing

Default Exports

● Export a single value


● Can use any name when importing

JS CALLBACK
A function is passed as a argument for another function

SYNCHRONOUS
Code will be executed from top to bottom

ASYNCHRONOUS
It starts with long running task that is performed along with other task in parallel manner
eg:settimeout()
JS PROMISE
Its a special object that represents whether the operation is success or failed(resolve,reject)

JS FETCH
It fetch the data from the server.req(api)=>res(json)
API
Application Programming interface it act as an intermediate between client request and server
response it give response based upon the specified request.

ASYNC AND AWAIT


ASYNC=>asynchronous function return the promise
AWAIT=>wait until the asynchronous function gets over,can only be used in asyn ,pause the
execution

You might also like