I got this

Publicado el: 30 enero 2024
en el canal de: 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


En esta página del sitio puede ver el video en línea I got this de Duración hora minuto segunda en buena calidad , que subió el usuario Code With Bubb 30 enero 2024, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 1,758 veces y le gustó 36 a los espectadores. Disfruta viendo!