Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Let 2/2 | Data Types and Variables
Introduction to JavaScript (staging)
course content

Contenido del Curso

Introduction to JavaScript (staging)

Introduction to JavaScript (staging)

1. Introduction
2. JavaScript syntax
3. Data Types and Variables

Let 2/2

<code class="go3679463865">let</code> 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.

123
var number = 5; var number = 3; console.log(number);
copy

But a variable declared with let does not allow redeclaration.

123
let number = 5; let number = 3; console.log(number);
copy

Tarea

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.

Tarea

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.

Note: Solution-2 is not much preferable.

<code class="go3679463865">let</code> 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.

123
planet = 'earth'; console.log(planet); var planet;
copy

But let does not allow hoisting.

123
planet = 'earth'; console.log(planet); let planet;
copy

Summary:

  • let is the newer way to declare variables.
  • let has block scope.
  • let does not allow redeclaration.
  • let does not allow hoisting.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 3. Capítulo 8
toggle bottom row

Let 2/2

<code class="go3679463865">let</code> 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.

123
var number = 5; var number = 3; console.log(number);
copy

But a variable declared with let does not allow redeclaration.

123
let number = 5; let number = 3; console.log(number);
copy

Tarea

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.

Tarea

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.

Note: Solution-2 is not much preferable.

<code class="go3679463865">let</code> 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.

123
planet = 'earth'; console.log(planet); var planet;
copy

But let does not allow hoisting.

123
planet = 'earth'; console.log(planet); let planet;
copy

Summary:

  • let is the newer way to declare variables.
  • let has block scope.
  • let does not allow redeclaration.
  • let does not allow hoisting.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 3. Capítulo 8
toggle bottom row

Let 2/2

<code class="go3679463865">let</code> 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.

123
var number = 5; var number = 3; console.log(number);
copy

But a variable declared with let does not allow redeclaration.

123
let number = 5; let number = 3; console.log(number);
copy

Tarea

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.

Tarea

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.

Note: Solution-2 is not much preferable.

<code class="go3679463865">let</code> 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.

123
planet = 'earth'; console.log(planet); var planet;
copy

But let does not allow hoisting.

123
planet = 'earth'; console.log(planet); let planet;
copy

Summary:

  • let is the newer way to declare variables.
  • let has block scope.
  • let does not allow redeclaration.
  • let does not allow hoisting.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

<code class="go3679463865">let</code> 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.

123
var number = 5; var number = 3; console.log(number);
copy

But a variable declared with let does not allow redeclaration.

123
let number = 5; let number = 3; console.log(number);
copy

Tarea

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.

Note: Solution-2 is not much preferable.

<code class="go3679463865">let</code> 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.

123
planet = 'earth'; console.log(planet); var planet;
copy

But let does not allow hoisting.

123
planet = 'earth'; console.log(planet); let planet;
copy

Summary:

  • let is the newer way to declare variables.
  • let has block scope.
  • let does not allow redeclaration.
  • let does not allow hoisting.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 3. Capítulo 8
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt