Javascript Function Variable Scope Question 2

Introduction

What is the output of the following code?

let a = "apple";

function myFunct() {
    a = "book";/*from   w  w w .  ja v  a  2  s.  co  m*/
    console.log(a);   
}

function myFunct2() {
    let a = "tree";
    myFunct();
    console.log(a);
}

myFunct2();  

console.log(a); 


book
tree
book



PreviousNext

Related