JavaScript 3



      
let num = [3, 5, 1, 2, 4] // for(let i=0; i { console.log(element * element) }) // Array.from let name = "Harry" let arr = Array.from(name) console.log(arr) // for...of for (let item of num){ console.log(item) } // for...in for (let i in num){ console.log(num[i]) }

JS Objects Literals

Used to store keyed collections & complex entities.
[Object literals like structure in c]

property => (key, value) pair
Objects are a collection of properties.
It is used to store complex data.

Scope

Scope determines the accessibility of variables, objects, and functions from different parts
of the code.

• Function
• Block
• Lexical

Function Scope
Variables defined inside a function are not accessible (visible) from outside the function.

Block Scope
Variables declared inside a {} block cannot be accessed from outside the block.

Lexical Scope
a variable defined outside a function can be accessible inside another function defined
after the variable declaration.
The opposite is NOT true.
ex -  nested function
?

Array Methods

  1. forEach
  2. map
  3. filter
  4. some
  5. every
  6. reduce
start me default parametere nahi de sakte hai, kyu ki function argument leta hai by order




  1. forEach 
ye kuch return nahi karta hai

2. filter

ye values return kar deta hai, jesa filter lagaoge

3. map

ye 
 bhi values return karta ha, ye filter se thora alag ha, ye sab pe lagu kar deta hai operation


chainning is also possible



0 Comments