Basic JavaScript - Global Scope and Functions DECLARATION/CALL

Need to understand why the fun2() is running if it is not called, i don’t see the fun2(); call, I just see the declaration, but the console show the two values of the variable

The console shows: myGlobal: 10 oopsGlobal: 5. But there is just one console.log(output); inside the declaration, not outside. Don’t understand what is happening there, could someone explain me please?

Your code so far

// Declare the myGlobal variable below this line
const myGlobal = 10;

function fun1() {
  // Assign 5 to oopsGlobal here
  oopsGlobal = 5;

// Only change code above this line

function fun2() {
  let output = "";
  if (typeof myGlobal != "undefined") {
    output += "myGlobal: " + myGlobal;
  if (typeof oopsGlobal != "undefined") {
    output += " oopsGlobal: " + oopsGlobal;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36 Edg/114.0.1823.58

Challenge: Basic JavaScript - Global Scope and Functions

Link to the challenge:

Maybe the “test feature” of FCC does it for you, setting you remain focus on the main challenge? Isn’t this the amazing part of FCC? :smile:

True hahahaha you know :sweat_smile:

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