Object in ES6. Code example open

Object in ES6. Code example

    const createCar = (name, model) => ({ name, model })

    const ford = createCar('Ford', 'Focus')

    console.log(ford)

    const yearField = 'year'

    const bmw = {
        name: 'BMW',
        ['model']: 'X6 Sport',
        [yearField]: 2018,

        logFields() {
            const { name, year, model } = this
            console.log(name, model, year)
        }
    }

    console.log(bmw)
    bmw.logFields()

    // const year = bmw.year
    const { year } = bmw
    console.log(year)
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation