constproduct={name:'Mac M1 256GB',price:1100,description:'This is a Mac M1 Chip with 256GB SSD',warrenty:'1 Year',stock:11,};const{name,price,featured=false}=product;console.log(`${name}, ${price}, ${featured}`);// Mac M1 256GB, 1100, false
Different Variable Names
constproduct={name:'Mac M1 256GB',price:1100,description:'This is a Mac M1 Chip with 256GB SSD',warrenty:'1 Year',stock:11,};const{name:productName,price:productPrice,featured:isProductFeatured=false}=product;console.log(`${productName}, ${productPrice}, ${isProductFeatured}`);// Mac M1 256GB, 1100, false
Nested Objects
constproduct={name:'Mac M1 256GB',price:1100,description:'This is a Mac M1 Chip with 256GB SSD',warrenty:'1 Year',stock:11,tech:{os:'iOS',logo:'./mac_m1.png',production_year:'2018',production_country:'USA',},};const{name:productName,tech:{os:productOS,logo:productLogo,expired=false},}=product;console.log(`${productName}, ${productOS}, ${productLogo}, ${expired}`);// Mac M1 256GB, iOS, ./mac_m1.png, false
constproduct={name:'Mac M1 256GB',price:1100,description:'This is a Mac M1 Chip with 256GB SSD',warrenty:'1 Year',stock:11,tech:{os:'iOS',logo:'./mac_m1.png',production_year:'2018',production_country:'USA',},};const{os:productOS,logo:productLogo,expired=false}=product.tech;console.log(`${productOS}, ${productLogo}, ${expired}`);// iOS, ./mac_m1.png, false
letfirstPhone='iPhone 13 Pro Max',secondPhone='iPhone 12 Pro Max';[firstPhone,secondPhone]=[secondPhone,firstPhone];console.log(`${firstPhone}, ${secondPhone}`);// iPhone 12 Pro Max, iPhone 13 Pro Max
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)