Basic JavaScript - Global Scope and Functions

Tell us what’s happening:
Am I doing anything wrong with this code?

  **Your code so far**
// Declare your variable here
var myGlobal=10;
function fun1(oopsGlobal) {
  // Assign 5 to oopsGlobal Here
// Only change code above this line
function fun2() {
  var 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/105.0.1343.27

Challenge: Basic JavaScript - Global Scope and Functions

Link to the challenge:


Inside function fun1 , assign 5 to oopsGlobal without using the var , let or const keywords.

Where did you assign 5 to oopsGlobal?


Using let or const , declare a global variable named myGlobal outside of any function. Initialize it with a value of 10 .

What key word did you use to delcare the global variable myGlobal?

1 Like

Please clarify your question/concern.
Are you just asking for a code review or are you trying to fix a bug (or other)?

myGlobal should be declared using the let or const keywords
This is the thing I need to have checked.

“var” is the variable for ‘myGlobal’

Thank you for the info.

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