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
- forEach
- map
- filter
- some
- every
- reduce
0 Comments