Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why eval('{a:23}') gives me 23 instead of {a:23}?

Tags:

javascript

I have this bit of javascript code in the browser

console.log( eval('{a:23}'));

and it prints 23

I was expecting instead to see

[Object]

can somebody explain ?

thanks

like image 577
Zo72 Avatar asked Dec 19 '25 04:12

Zo72


1 Answers

In that context, { starts a block, not an object literal.

a: is then a label.

That leaves 23.

like image 113
Quentin Avatar answered Dec 20 '25 18:12

Quentin