es6 Temporal dead zone
Ad
I know Temporal dead zone in es6. But I was confused about the procedure of the following code.
Javascript is a kind of Interpretive language.How does it knows there is a s will be declared in this block behind rather than use the s outside this block.
In an other word , what is the procedure of the following code ?? I am new here, please help me.
'use strict'
var s = 1;
if (true){
console.log(s);
console.log("AAA");
let s = 2;
}
Ad
Answer
Ad
Javascript code is run in multiple passes. A first pass will go through and deal with all the declarations and assign them to their scopes.
That's how it "knows" that a left hand side reference to "s" will be declared via let for the scope of that if{} block, even though the non-hoisted let hasn't actually declared it yet.
Ad
source: stackoverflow.com
Related Questions
Ad
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad