Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //simple(for loop, while loop, do while)
- //specific to array(simple loop + extra way(for of, forEach, map, reduce, find, filter, findIndex, every, some))
- // array helper method
- //specific object(for in)
- //foreach
- // const nums = [1, 2, 3, 4]
- // let total = 0
- // nums.forEach(num => total += num)
- // console.log(total)
- //map
- // works on array
- // manipulate every element of array
- //return an array
- // don't modify the existing array
- // const nums = [1, 2, 3, 4]
- // const result = nums.map(num => {
- // return num * 3
- // })
- // const numbers = [50, 30, 90, 25]
- // const result = numbers.map(num => num < 33 ? 'Fail': 'pass'
- // )
- // console.log(result)
- // console.log(nums)
- //find
- // works on array
- // find an element(first occurrence)
- //return a value
- // don't modify the existing array
- // const nums = [1, 2, 3, 4, 5, 6]
- // const result = nums.find(num => num > 4)
- // console.log(result)
- //filters
- // works on array
- // find elements based on condition(first occurrence)
- //return an array
- // don't modify the existing array
- // const nums = [1, 2, 3, 4, 5, 6]
- // const result = nums.filter(num => num > 4)
- // console.log(result)
- //some
- // works on array
- // // return true/false if one element is true based on condition
- //return an single value(true/false)
- // don't modify the existing array
- // const nums = [1, 2, 3, 4, 5, 6]
- // const result = nums.some(num => num > 4)
- // console.log(result)
- //every
- // works on array
- // return index if every element is true based on condition
- //return an single value(true/false)
- // don't modify the existing array
- // const nums = [1, 2, 3, 4, 5, 6]
- // const result = nums.every(num => num >= 1)
- // console.log(result)
- //findIndex
- // works on array
- // return index number of first occurrence based on condition
- //return an single value
- // don't modify the existing array
- // const nums = [1, 2, 3, 4, 5, 6]
- // const result = nums.findIndex(num => num === 7)
- // console.log(result)
- //reduce
- // const nums = [1, 2, 3, 4, 5, 6]
- //1) prev - 1
- //curr- 2
- //2) prev-what you return
- //curr -3
- //3)prev-what you return
- //curr -4
- // const result = nums.reduce((previousValue, currentValue) => {
- // // console.log(previousValue)
- // // console.log(currentValue)
- // return previousValue + currentValue
- // // return 'Hello'
- // })
- // const result = nums.reduce((previousValue, currentValue) => {
- // // console.log(previousValue)
- // // console.log(currentValue)
- // return previousValue + currentValue
- // // return 'Hello'
- // }, 0)
- // console.log(result)
- //Hoisting (Lifting up)
- // var a = 1
- // console.log(a)
- // var a = 1
- // console.log(a)
- // console.log(sayHi)
- // function sayHi(){
- // return 'Hi'
- // }
- // const sayHi = () => {
- // return 'Hi'
- // }
- // console.log(sayHi())
- //preparation stage
- //1)Declaration
- //2) function block in memory
- //execution stage
- //calling, assignment
- //preparation stage
- var a
- function sayHi(){
- return 'Hi'
- }
- //execution phase
- console.log(a)
- a = 1
- console.log(a)
- console.log(sayHi())
- console.log(sayHi())
- //temporal dead zone(Let , Const)
Add Comment
Please, Sign In to add comment