GoConqr has a new look! Let us know what you think.

Flashcards

objects

milly larcen Object English 2 cards

Cards in this deck (2)

  1. 1way to check if an object has a propertyconst user = { name: 'Olivier',}
    'name' in user // true
    in operator checks if the property is in the specified object or its prototype chain, so 'constructor' in user // true
    hasOwnProperty method indicates if the object has the specified property as its own property.
    myObject.hasOwnProperty('id')
    It is recommended to use: Object.prototype.hasOwnProperty.call(myObject, 'id') instead
    What is the difference and why should you use the second syntax ?
    1
    You can create objects without any prototype in javascript this way:
    const myObject = Object.create(null). Why would you do that instead of const myObject = {}?
    Because it was apparently a way to simulate a map data structure (you would still get an object but without any properties or methods inherited from the prototype) before they introduce the Map data structure.
    2
    u can overwrite the hasOwnProperty method (or any other method) and thus:
    const user = { name: 'Olivier' }
    user.hasOwnProperty = null
    user.hasOwnProperty('name') // Uncaught TypeError
    Object.prototype.hasOwnProperty.call(user, 'name') // true
  2. 2destructuringvar obj ={color: "blue"}
    console.log(obj.color);
    ***
    var { color, name} = { color: "blue", name: "John", city: "NY"}
    console.log(color);

Information

Description
Object Flashcards on objects, created by milly larcen on 16/04/2020.
Created by
milly larcen
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?