Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // const arr = [1, 2, 3,[3, [5, 6]], 6, 7]
- // console.log(arr[3][1][0] + arr[3][1][1])
- // function sum(arr){
- // let sum = 0
- // const nestedArr = arr[3][1]
- // for(let num of nestedArr){
- // sum += num
- // }
- // return sum
- // }
- // console.log(sum(arr))
- //nested object access
- // const obj = {
- // a: 1,
- // b: 2,
- // c: {
- // d: 1,
- // e: 2,
- // f: {
- // g() {
- // return 1
- // }
- // }
- // }
- // }
- // console.log(obj.c.f.g())
- //first class function(criteria)
- //can be assigned as variable value, passed as an arguments, returned from function
- // const func1 = function (myFunc) {
- // return myFunc() + 1
- // }
- // const func2 = function(){
- // return 2
- // }
- // console.log(func1(func2))
- // function sum(number1) {
- // return function(number2){
- // return number1 + number2
- // }
- // }
- // console.log(sum(4)(3))
- // console.log(sum(3)(4))
- //default parameter
- // function multiply(num1 = 10, num2 = 50, num3 = 7) {
- // console.log(num1, num2, num3)
- // console.log(num1 * num2 * num3)
- // }
- // multiply(20, null, 5)
- // const num1 = 10
- // function printNum (num){
- // // console.log(num)
- // return num
- // }
- // // printNum(num1)
- // console.log(printNum(num1))
- //array destructuring
- // const myArr = [1, 2, 3]
- // const num1 = myArr[0]
- // const num2 = myArr[1]
- //destructuring
- // const [num1,,num3] = myArr
- // console.log(num1, num3)
- //object destructuring
- // const myObj = {
- // a: 1,
- // b: 2,
- // c: [3, 4]
- // }
- // const val1 = myObj.a
- // const val2 = myObj.b
- // const val3 = myObj.c.d
- // const {b: val2, a: val1, c: [ran1, ran2]} = myObj
- // console.log(val2, val1, ran1, ran2)
- // console.log(val1, val2, val3)
- //array spreading and rest
- const myArr = [1, 2, 3]
- //spread
- const newArr = [...myArr, 4]
- //rest
- const [num1, ...restValues] = newArr
- console.log(num1, restValues)
- const myObj = {
- a: 1,
- b: 2,
- c: [3, 4]
- }
- //spread
- const newObj = {
- ...myObj,
- d: 5
- }
- console.log(newObj)
- //rest
- const {a, ...rest} = newObj
- console.log(a, rest)
- //1.data naming issue
- //2. order issue
- function getProfileInfo({age, firstName, lastName}){
- console.log(`${firstName} ${lastName}-${age}`)
- }
- //special case
- function getProfileInfo(...profile) {
- console.log(profile)
- console.log(`${profile[0].firstName} ${profile[0].lastName} - ${profile[0].age }`)
- // console.log(`${firstName} ${lastName}-${age}`)
- }
- getProfileInfo({
- firstName: 'samim',
- lastName: 'Hasan',
- age: 28
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement