Basic javascript:local scope

Basic javascript:local scope
0

#1

hi everyone, my doubt is regarding, the task I mentioned above , here is the code snippet:

function myLocalScope() {
  var myVar='use strict'; // you shouldn't need to edit this line
  
  console.log(myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);

// Now remove the console log line to pass the test

now my output after i remove the console.log(myVar);, i should get only 1 ouput, that is :use strict, since the fuction is called only one time right.
But i am getting the output: use strict ,two times. I am confused, as to why it is displaying it two times.
here is the link to the task: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions/

thnks in advance


#2

Why are you assigning ‘use strict’ to myVar


#3

it was said in the task.


#4

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


#5

No it wasn’t.

Declare a local variable myVar inside myLocalScope. Run the tests and then follow the instructions commented out in the editor.

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);

// Now remove the console log line to pass the test

‘use strict’ is a directive