-2

how it is working for both ? I gave string for one thing and for other I just gave reference but it is working for both please look at draw and 'draw' it is working for both without any error may I know the reason behind it?

k={
    draw:function(){
        console.log("drawing")
    }
}

p={
    'draw':function(){
        console.log("drawing 2")
    }
}
k.draw()
p.draw()
Indratej Reddy
  • 165
  • 1
  • 7
  • 1
    'draw' is a property, so `draw` and `"draw"` are identical. `function () {` is the function, it's just an anonymous function. – Keith Mar 29 '21 at 08:16

1 Answers1

0

when the first character of the key is not a number, object.key and object['key'] is same

  • 3
    It's not only numbers that you need quotes for. Lots of other characters are not allowed in a non-quoted property name. – jfriend00 Mar 29 '21 at 08:13