Question about console output in "Global Scope and Functions"


I have a question about the Global Scope and Functions test.

My code looks like this:

// 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;

The console output looks like this:

// running tests
// tests completed
// console output
myGlobal: 10 oopsGlobal: 5

I was wondering why console.log(output) in the fun2 function is executed, despite the fun2 function not being called anywhere in the code.

For instance, in the description of Local Scope and Functions, which comes after this test, the myTest function has to be called in order for the console.log to output anything.

The tests have to run the function to make sure that it does the right thing

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