Using strict mode in the Node.js REPL
If you want to use strict mode [1] in the Node.js REPL, you have two options.
(Assigning to a read-only property fails silently in sloppy mode.)
Afterwards, everything you write in the REPL is interpreted in strict mode:
Option 1. Start the REPL as usual, wrap your code in an IIFE [2]:
> (function () { 'use strict'; 'abc'.length = 1 }());
TypeError: Cannot assign to read only property 'length'
(Assigning to a read-only property fails silently in sloppy mode.)
Option 2. Use the Node.js command line option --use_strict:
node --use_strict
Afterwards, everything you write in the REPL is interpreted in strict mode:
> 'abc'.length = 1
TypeError: Cannot assign to read only property 'length'
References:
Comments
Post a Comment