Skip to content
Advertisement

Tag: syntax

JavaScript property access: dot notation vs. brackets?

Other than the obvious fact that the first form could use a variable and not just a string literal, is there any reason to use one over the other, and if so under which cases? In code: Context: I’ve written a code generator which produces these expressions and I’m wondering which is preferable. Answer (Sourced from here.) Square bracket notation

Why do results vary based on curly brace placement?

Why do the code snippets below, taken from this article, produce different results due to only a single change in the placement of curly braces? When the opening curly brace { is on a new line, test() returns undefined, and “no – it broke: undefined” is displayed in the alert. When the brace is on the same line as return,

Advertisement