Changing global variables in JavaScript

Note that the global variable will only change at the time the function is called. If there is no function call, the variable will not change:

javascriptlet num = 1;

function func() {
  num = 2; // let was not written - changes external variable
  console.log(num);
}
// func(); - function call commented out

console.log(num); // shows 1 - variable hasn't changed

And now let's demonstrate with code that the global variable will change only after the function is called:

javascriptlet num = 1;

function func() {
  num = 2;
}

console.log(num); // shows 1
func(); // change the variable
console.log(num); // shows 2
Задание 1

Determine what will be output to the console without running the code:

javascriptlet num = 1;

function func() {
  num = 2;
}
func();

console.log(num);
Задание 2

Determine what will be output to the console without running the code:

javascriptlet num = 1;

function func() {
  num = 2;
}

console.log(num);
Задание 3

Determine what will be output to the console without running the code:

javascriptlet num = 1;

function func() {
  let num = 2;
}
func();

console.log(num);
Задание 4

Determine what will be output to the console without running the code:

javascriptlet num = 1;

function func() {
  let num = 2;
}

console.log(num);
func();
Задание 5

Determine what will be output to the console without running the code:

javascriptlet num = 1;

function func() {
  num = 2;
}

console.log(num);
func();
Задание 6

Determine what will be output to the console without running the code:

javascriptlet num = 1;

function func() {
  num++;
}

func();
func();
func();
console.log(num);
Задание 7

Determine what will be output to the console without running the code:

javascriptfunction func() {
  num = 2;
}

let num = 1;
console.log(num);
func();
Задание 8

Determine what will be output to the console without running the code:

javascriptfunction func() {
  num = 2;
}

let num = 1;
func();
console.log(num);