JavaScript why object.keys() to Object literal and Object.create() has different result? object keys object values,object.keys(object),object.keys object.

mdn Object.keys() defines it will return an array of a given object's own enumerable properties.

var USComicPublishers = {
countryOfOrigin : {
    value  : "USA",
    enumerable: false,
    writable: false,
    configurable: false
},
medium : {
    value  : "comic books",
    enumerable: true,
    writable: false,
    configurable: false
}
}

as the Object.keys() define, it should return ['medium']

but it return ['countryOfOrigin', 'medium']

then I use Object.create() to wrap it, it will return ['medium']

var us2 = Object.create({}, USComicPublishers)
console.log(us2)
// return ['medium']

does Object literal has different behavior in Object.create()?

var USComicPublishers = {
    countryOfOrigin : {
        value  : "USA",
        enumerable: false,
        writable: false,
        configurable: false
    },
    medium : {
        value  : "comic books",
        enumerable: true,
        writable: false,
        configurable: false
    }
}
console.log(Object.keys(USComicPublishers))
var us2 = Object.create({}, USComicPublishers)
console.log(Object.keys(us2))
console.log(Object.getOwnPropertyNames(us2))
Answer:1

Yes, there is a difference. When creating an object literal, it's not possible to set the enumerable, writable and configurable properties like that. Instead, you're setting properties with all those values set to true and value set to the value you're giving (you'll notice in your first example that USComicPublishers.medium will be an object and USComicPublishers.medium.value === "comic books")

You would have to create the object literal and then apply the properties using Object.defineProperties if you wanted the same results.

var USComicPublishersData = {
    countryOfOrigin : {
        value  : "USA",
        enumerable: false,
        writable: false,
        configurable: false
    },
    medium : {
        value  : "comic books",
        enumerable: true,
        writable: false,
        configurable: false
    }
}
var USComicPublishers = {};
Object.defineProperties(USComicPublishers, USComicPublishersData);
console.log(Object.keys(USComicPublishers))
Answer:2

I have some abstract question. Lets say I have a website which uses 1000+ JS script files. (Not at once, but in the overall 1000+ JS scripts are needed if user goes through all existing flows). I ...

I have some abstract question. Lets say I have a website which uses 1000+ JS script files. (Not at once, but in the overall 1000+ JS scripts are needed if user goes through all existing flows). I ...

  1. javascript dynamic loading of script
  2. javascript dynamic loading content
  3. dynamic loading javascript library
  4. javascript dynamic loading jquery
  5. angular dynamic javascript loading
  6. html dynamic javascript loading
  7. javascript dynamic module loading
  8. dynamic page loading javascript
  9. dynamic script loading javascript async
  10. javascript dynamic resource loading
  11. javascript dynamic code loading
  12. javascript dynamic image loading
  13. loading dynamic javascript files

Actually I am dealing with the problem to let my code work in IE. Unfortunately this is still necessary. Polyfills for unsupported methods are working fine. But I wonder, how / if I can make "const" ...

Actually I am dealing with the problem to let my code work in IE. Unfortunately this is still necessary. Polyfills for unsupported methods are working fine. But I wonder, how / if I can make "const" ...

I have this code, i want that this two Promise runs sequentially and result should be like this: a progress: 20 a progress: 40 a progress: 60 a progress: 80 a progress: 100 a resolve: a b progress: ...

I have this code, i want that this two Promise runs sequentially and result should be like this: a progress: 20 a progress: 40 a progress: 60 a progress: 80 a progress: 100 a resolve: a b progress: ...

I have two objects. First one have entire school full details of students record. Example like var first = { students: [ { id:'1', name:"suresh", age:"20", degree:"BSc", status:"obsent"}, ...

I have two objects. First one have entire school full details of students record. Example like var first = { students: [ { id:'1', name:"suresh", age:"20", degree:"BSc", status:"obsent"}, ...