• Post author:
  • Post category:Blog
  • Reading time:2 mins read
  • Post last modified:June 12, 2024

Analyze the code snippet. Identify which variables are local and which are global;

let name;
let age;
{
      let profession;
      {
             let height;
             let weight;
       }
  • name ==> Global 
  • profession ==> Local 
  • age ==> Global 
  • height ==> Local 
  • weight ==> Local 
Answers Explanation & Hints:

In the given code snippet, the variables can be classified as follows:

Global variables:

  • name
  • age

Local variables within the innermost block:

  • pofession
  • height
  • weight

Based on the scope of the variables, name and age are global variables as they are declared outside of any specific block or function. They can be accessed and modified throughout the entire code.

On the other hand, height and weight are local variables because they are declared within the innermost block, which is nested inside the outer block. These variables have a limited scope and can only be accessed within the block in which they are declared.

For more Questions and Answers:

JavaScipt Essentials 1 (JSE) | JSE1 – Module 2 Test Exam Answers Full 100%

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments