Using "let" as a variable name does not cause errors in google v8

I wrote random code in the Chrome console. To my surprise, chrome let me use letas a variable name, which is completely wrong, as it letis a reserved keyword. I need to understand why this is happening.

Scenarios:

var const = 78 //throws an error as expected

var function = 46 //throws an error as expected

var let = 56 //didn't throw an error :O

let //prints 56, which is wrong because 'let' is a keyword

let ab = 90

ab //prints 90 as expected

This flaw exists in node. But, when I try it in Babel REPL , it throws an error.

I think this is related to Google v8

+4
source share
2 answers

. .

JavaScript FutureReservedWord:

implements     interface   let       package    private
protected      public      static    yield

; :

SyntaxError: Cannot use the reserved word 'let' as a variable name in strict mode.

, pre-ES2015 - - let , , , , JS .

+6

ES6 .

( ) . Node , "use strict"; .

Chrome, :

"use strict";
var let = 43;
// Throws: Uncaught SyntaxError: Unexpected strict mode reserved word
Hide result
+6

Source: https://habr.com/ru/post/1660664/


All Articles