2. Display hello
Variable bnane ke 3
tarike:
Issue with var type
Issue 1.Output will be undefine but error ana chahiye tha
Becs js engine is code ko mence
“Var x” ko top me patak deta hai
This concept(variable declaration shift to top) is called variable Hoisting
Hoisting is JavaScript's default behavior of moving
declarations to the top.
Note : Let n const type return error
instead of undefine becs it will not hoist
‘Var ‘Issue 2.Also here redeclaration are allowed but
in ‘let’ not allowed
Output: here 30 is overriten with 60
But not to be an error while it is declared erlier
too
But gives error in ‘let’ redeclaration
Output:
Var issue 3.scoping issue output
No issue with ‘let’ Output:
Const cant be changed or redeclared
4. is a non-premitive data type in JS
It will store values in key: value pair
or
Or using ‘object destructuring’ ,we will pull out or khinch liya from inside object
For code cleaner or not repeted
or
U can rename as:
5. Key and value can be with same name
So ,it can be written direct :
Js function can be called before definition
due to function hoisting by js engine
So this is an issue that Function ko ek constant
me assign kr denge
that can ve solved
by using arrow function
output
parameterise
or
returning
Single sttement definitin can be written without {}
And return keyword for return
Object passing as a function argument n destructing n callin
Object destructuring direct inside parameter
6. Returning object
If is single line : Here we must give () becs js engine ko batana
padega ki object hai na ki function ki body
N we can get result
There are 7 primitive data types: string, number,
bigint, boolean, undefined, symbol, and null.
Rteference type act as a pointer in c,
If we change refrenced variable or object value then will be
changed in actual object vaor variable value
Here we change value of
obj1 but changed obj2 too
Premitive me copy variable me
value change hone se actual variable
me value koi change ni hota hai
Output:
output
Same in array becs array is also reference type:
Output:
7. Actual way to copy an object using
spread operator(...)
Output:
... obj se chije bahar (unpack hona )
nikal jati hai n fir se ek object ke
inside wrap kr diya As below :
Spread operator is usefull when copy of
another object values in new object with
adding or replace more item
Add item:
Replace item:
Output:
Copy array usning spread (...) operator
... Sprd oprtr se unpack ho gya the wapis
Se arr [] oprtr use krke pack kr diya
8. Copy two arrays into another array
output
Array destructuring
Array
iteration:
Using call back function in for each:
Array of objects inside array:
9. Change array objects value inside array:
Array Map:
Use for iterate array meanwhile
returns a new array:
Array Filter:
Or in single line if contain singe line
Dynamically remove items from array by passing parameter:
10. Filter multiple values by given condition:
Fetch method:returns promises that promiss to return sure or reject
If return then output in array object fron json(http) response
If single line return