browser-console

Why does commuting the arguments of == in a console change the output?

回眸只為那壹抹淺笑 提交于 2019-12-22 05:02:49
问题 If I open my browser console (tested in Chrome/Firefox) and type: null == {} I get: false However, if I commute both arguments to the == operator and instead type: {} == null I get: Uncaught SyntaxError: Unexpected token == Image: Why does this happen? Why does this only happen in a console and not when the browser executes a script within an HTML page? EDIT: While question 35812626 addresses this and explains the cause as JS parsing the {} as a code block, it uses the triple equals (strict

Why does commuting the arguments of == in a console change the output?

一个人想着一个人 提交于 2019-12-05 04:19:08
If I open my browser console (tested in Chrome/Firefox) and type: null == {} I get: false However, if I commute both arguments to the == operator and instead type: {} == null I get: Uncaught SyntaxError: Unexpected token == Image: Why does this happen? Why does this only happen in a console and not when the browser executes a script within an HTML page? EDIT: While question 35812626 addresses this and explains the cause as JS parsing the {} as a code block, it uses the triple equals (strict comparison) operator === , not the double equals == . As a user points out below, a code block can