javascript - When does JS interpret {} as an empty block instead of an empty object? -



javascript - When does JS interpret {} as an empty block instead of an empty object? -

i reading reply question (about "wat" video) , said:

{}+[] interpreted empty block of code, unary plus , empty array. first part nothing, array converted comma-separated string of it's elements (empty string empty array), number (empty string converted 0), hence 0.

i learning js "the definitive guide" seek understand things that.

my question is, when js decide interpret {} empty block of code, instead of empty object?

also, there inconsistencies between node.js , firebug understand.

firebug:

node.js:

let's @ language grammar, shall we? section 12, statements:

statement : block variablestatement emptystatement expressionstatement ...lots of other stuff...

that's fancy way of saying statement can block, variable statement, empty statement, look statement, or lots of other stuff. notice first alternative there 'block':

block : { statementlist(opt) } statementlist : statement statementlist statement

which again, fancy way of saying block {, optionally followed bunch of statements, followed }.

and that's see in example: before javascript parser thinks have object literal (which defined somewhere under expressionstatement, 4th thing 'statement' be), first thinks have 'block'.

edit: if want, can see live in javascript engine's source code:

in v8, chrome's javascript engine, go parser::parsestatement. first thing checks whether we're on {, , if does, parses block. in spidermonkey, firefox's javascript engine, go parser::statement 1 time again see the first check beingness against { , parsing block statement.

regarding sec question, that's been covered great detail on question. summarise in sentence: node.js treats input if look (thus can't 'block'), while firebug/chrome dev tools treat 'statement'.

javascript node.js firebug

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -