Javascript Function Variable Scope Question 1

Introduction

What is the output of the following code?

let a = "apple";
console.log(a); //  w  w w  .  j  av a 2  s  .  c  o m
function myFunct() {
    console.log(a);
    a = "book";
    console.log(a);
}

myFunct();   

console.log(a);


apple
apple
book
book



PreviousNext

Related