Files
codeql/javascript/ql/test/query-tests/Declarations/TemporalDeadZone/tst.js
2018-08-02 17:53:23 +01:00

45 lines
677 B
JavaScript

function f() {
// NOT OK
s = null;
let s = "hi";
// OK
s = "hello";
}
function g() {
// OK
s = null;
var s = "hi";
// OK
s = "hello";
}
function do_something() {
// OK
let foo;
let foo;
}
function do_something() {
// OK
let foo;
foo = "bar";
let foo;
}
if (true) { // enter new scope, TDZ starts
const func = function () {
console.log(myVar); // OK!
};
function otherfunc() {
console.log(myVar); // also OK
}
// Here we are within the TDZ and
// accessing `myVar` would cause a `ReferenceError`
let myVar = 3; // TDZ ends
func(); // called outside TDZ
}