I got this

Veröffentlicht am: 30 Januar 2024
auf dem Kanal: Code With Bubb
1,758
36

What will be the output from this code?

function sayHi() {
console.log(name);
console.log(age);
var name = 'Lydia';
let age = 21;
}

sayHi();

A: Lydia and undefined
B: Lydia and ReferenceError
C: ReferenceError and 21
D: undefined and ReferenceError

An interesting question which highlights the difference between the let and var keywords in JavaScript. The key thing here to know is that although the var keyword (don't use it!) is hoisted to the top of the function scope, the value is not assigned to the variable until later on so D is the correct answer as we'll get undefined from the name variable and an error because the age variable is not yet declared.

#javascript #shorts


Auf dieser Seite können Sie das Online-Video I got this mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Code With Bubb 30 Januar 2024 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,758 Mal angesehen und es wurde von 36 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!