Ramatou Adamou Issa

Ramatou Adamou Issa

  • Experiences
  • Formation
  • Musics
  • Blog

›Recent Posts

Recent Posts

  • Watchtower, container for updating docker images
  • PHP8 (Migrating existing PHP7 project to PHP8)
  • What news in Symfony 5
  • Command Query Segregation Responsibility (CQRS)
  • AFUP conference feedbacks

ES6 - Destructuring

May 7, 2019

Nicolás Bevacqua

Set variables values by object destructuring.

Destructuring first level


    const pony = { foo: 'foo test' }
    
    const { foo } = pony
    
    //foo value is equal to = pony.foo = 'foo test'  
     

Destructuring with alias


    const pony = { foo: 'foo test with alias' }
    
    const { foo: baz }  = pony
    
    //baz value is equal to pony.foo = 'foo test with alias'
    

Destructuring with default value


const pony = {}

const { foo='default value' } = pony

//foo value is equal to pony.foo with 'default value' default value

Destructuring Level 2:


    const pony = {
        foo: {
            baz: 'baz'
        }        
    }

    const { foo: baz } = pony
    
    //baz value will be 'baz'

Destructuring response level 0 and nested


1. Destructuring level 0 raise undefined is the variable not does not exist
2. Destructing nested level raise an error when the variable does not exist

Destructing in function parameters


function foo(bar={a: 1, b: 2}) {
}
Tweet
Recent Posts
  • Set variables values by object destructuring.
Ramatou Adamou Issa
Ramatou Adamou Issa
HomeExperiencesFormation
Social Networks
InstagramTwitterChat
Accounts
Gallery photoBlogGitHubStar
Copyright © 2025 Ramazaki