The different scopes of a variable in JavaScript are:

1. Global Scope: A global scope variable is declared outside of any function and can be accessed from any part of the program.

Example:
var x = 10;

2. Local Scope: A local scope variable is declared inside a function and can only be accessed within that function.

Example:
function myFunction() {
var y = 20;
}

3. Block Scope: A block scope variable is declared inside a block statement and can only be accessed within that block statement.

Example:
if (true) {
let z = 30;
}

Leave a Reply

Your email address will not be published. Required fields are marked *