Basic JavaScript - Local Scope and Functions

Tell us what’s happening:
Hi.
I checked the “hint” and also the video, the code is exactly like on the video. I’ve been looking at it for the past hour and cant understand what is wrong… It doesn’t let me pass. I tried without console.log, still nothing…

Anyone could help, please? Thanks!
Your code so far

function myLocalScope() {
  var myVar = 5;
  console.log(myVar);
}
myLocalScope();

console.log(myVar);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Local Scope and Functions

Link to the challenge:

El fragmento de código que has proporcionado contiene un error. El error es que estás tratando de acceder a la variable myVar fuera de la función myLocalScope, y myVar está definida dentro de la función, por lo que no es una variable global.

Recuerda que el uso de variables globales debe hacerse con precaución, ya que puede llevar a problemas de mantenimiento y depuración en programas más grandes

The code snippet you provided contains an error. The error is that you are trying to access the variable myVar outside the function myLocalScope, and myVar is defined inside the function, so it is not a global variable.

Remember that the use of global variables should be done with caution, as it can lead to maintenance and debugging problems in larger programs

Can you please point out which of the two tests fail when you hit the “Run the tests (Ctrl + Enter)” button? It will help me determine why you are failing the challenge.

In English: Yes Bruno but that is not the reason why the tests failed.

In Spanish: Sí Bruno pero esa no es la razón por la que las pruebas fallaron.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.