I am trying to write some ES6 code in chrome console but i ran with some errors. How can i run the ES6 scripts in console?
For example, given the input
let type='grizzle';
the console records a SyntaxError
with the message
Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
as shown in the following screenshot
5 Answers. Show activity on this post. In Chrome, most of the ES6 features are hidden behind a flag called "Experimental JavaScript features". Visit chrome://flags/#enable-javascript-harmony , enable this flag, restart Chrome and you will get many new features.
Safari, Chrome, Firefox and Edge all support the ES6 Modules import syntax.
Press Command+Option+J (Mac) or Control+Shift+J (Windows, Linux, ChromeOS) to open the Console, right here on this very page.
UPDATE: As of late 2019, you can just use let
in the console.
As the error message states, some ES6 features are not available outside of strict mode. Therefore, to take advantage of those features, you must first create a strict-mode block.
From the console, the easiest way to use strict mode is by creating an Immediately-Invoked Function Expression (IIFE). For example,
(function() { "use strict"; let x = "asdf"; }());
will behave as intended when entered in the console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With