Search code examples
node.jsecmascript-6string-literalstemplate-literals

ECMA Script 2015 (ES6) On NodeJS Without Flags


According to this article, many ES6 functions (particularly template literals, formally known as 'template strings') are enabled by default.

The below was entered into the terminal:

user@host: node
> "test string: ${10+4}"
'test string: ${10+4}'

Even when using the '--harmony' flag, template literals are not being executed as code and are instead being treated like strings.

My version is as follows:

user@host: node -v
v5.7.0

Any suggestions would be greatly appreciated.


Solution

  • Template strings are surrounded by ` (back quote) character:

    `test string: ${10+4}`