Let 2/2
let Does Not Allow Redeclaration
Redeclaration means declaring a variable again. As discussed in the previous chapter, we can redeclare the variable again and again with var but we cannot do that with the let keyword.
123var number = 5; var number = 3; console.log(number);
But a variable declared with let does not allow redeclaration.
123let number = 5; let number = 3; console.log(number);
Swipe to start coding
A variable named country with two values Pakistan and England has been given declared for you using the let keyword but this code wonβt run because let doesnβt allow redeclaration. Your task is to make changes in the below code so that we England as the output. There are two possible ways to do get the desired result.
Solution
Note: Solution-2 is not much preferable.
let Does Not Allow Hoisting
As discussed in the previous chapter, let does not allow hoisting i.e. we cannot use a variable before the declaration. Variables declared with the var keyword can be accessed or used before the declaration, for example.
123planet = 'earth'; console.log(planet); var planet;
But let does not allow hoisting.
123planet = 'earth'; console.log(planet); let planet;
Summary:
letis the newer way to declare variables.lethas block scope.letdoes not allow redeclaration.letdoes not allow hoisting.
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Summarize this chapter
Explain the code in file
Explain why file doesn't solve the task
Awesome!
Completion rate improved to 2
Let 2/2
Swipe to show menu
let Does Not Allow Redeclaration
Redeclaration means declaring a variable again. As discussed in the previous chapter, we can redeclare the variable again and again with var but we cannot do that with the let keyword.
123var number = 5; var number = 3; console.log(number);
But a variable declared with let does not allow redeclaration.
123let number = 5; let number = 3; console.log(number);
Swipe to start coding
A variable named country with two values Pakistan and England has been given declared for you using the let keyword but this code wonβt run because let doesnβt allow redeclaration. Your task is to make changes in the below code so that we England as the output. There are two possible ways to do get the desired result.
Solution
Note: Solution-2 is not much preferable.
let Does Not Allow Hoisting
As discussed in the previous chapter, let does not allow hoisting i.e. we cannot use a variable before the declaration. Variables declared with the var keyword can be accessed or used before the declaration, for example.
123planet = 'earth'; console.log(planet); var planet;
But let does not allow hoisting.
123planet = 'earth'; console.log(planet); let planet;
Summary:
letis the newer way to declare variables.lethas block scope.letdoes not allow redeclaration.letdoes not allow hoisting.
Thanks for your feedback!
single