mirror of
https://github.com/github/codeql.git
synced 2025-12-18 09:43:15 +01:00
45 lines
677 B
JavaScript
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
|
|
}
|