Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Var 2/3 | 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

Var 2/3

Var Tolerate Redeclaration

Var tolerates the redeclaration. If a variable is declared with the same name twice with var we will not get an error, but with let we will get an error. For instance:

12
let user = 'Mike'; let user = 'John';
copy

But we can declare variables with the same names with var and the old values of the variables are simply overwritten, for example.

123
var user = 'Mike'; var user = 'John'; console.log(user)
copy

Tarea

Declare a variable company and assign the value " Apple". Redeclare the company and now set the value “Samsung” by using the var keyword. Show the updated value on the console.

Tarea

Declare a variable company and assign the value " Apple". Redeclare the company and now set the value “Samsung” by using the var keyword. Show the updated value on the console.

Variable hoisting

Hoisting, in JavaScript, is a way where a function or a variable can be used before its declaration.
In JavaScript, var is hoisted while the let and const does not allow hoisting, for example.

123
totalNumber = 10; console.log(totalNumber); var totalNumber;
copy

If we use the variable inside console.log() and nothing is written before it we will get an undefined value. In JavaScript first, the memory is allocated to the variable and initially, their values are undefined after this they are assigned some values.

12
console.log(company) var company="panasonic";
copy

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 5
toggle bottom row

Var 2/3

Var Tolerate Redeclaration

Var tolerates the redeclaration. If a variable is declared with the same name twice with var we will not get an error, but with let we will get an error. For instance:

12
let user = 'Mike'; let user = 'John';
copy

But we can declare variables with the same names with var and the old values of the variables are simply overwritten, for example.

123
var user = 'Mike'; var user = 'John'; console.log(user)
copy

Tarea

Declare a variable company and assign the value " Apple". Redeclare the company and now set the value “Samsung” by using the var keyword. Show the updated value on the console.

Tarea

Declare a variable company and assign the value " Apple". Redeclare the company and now set the value “Samsung” by using the var keyword. Show the updated value on the console.

Variable hoisting

Hoisting, in JavaScript, is a way where a function or a variable can be used before its declaration.
In JavaScript, var is hoisted while the let and const does not allow hoisting, for example.

123
totalNumber = 10; console.log(totalNumber); var totalNumber;
copy

If we use the variable inside console.log() and nothing is written before it we will get an undefined value. In JavaScript first, the memory is allocated to the variable and initially, their values are undefined after this they are assigned some values.

12
console.log(company) var company="panasonic";
copy

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 5
toggle bottom row

Var 2/3

Var Tolerate Redeclaration

Var tolerates the redeclaration. If a variable is declared with the same name twice with var we will not get an error, but with let we will get an error. For instance:

12
let user = 'Mike'; let user = 'John';
copy

But we can declare variables with the same names with var and the old values of the variables are simply overwritten, for example.

123
var user = 'Mike'; var user = 'John'; console.log(user)
copy

Tarea

Declare a variable company and assign the value " Apple". Redeclare the company and now set the value “Samsung” by using the var keyword. Show the updated value on the console.

Tarea

Declare a variable company and assign the value " Apple". Redeclare the company and now set the value “Samsung” by using the var keyword. Show the updated value on the console.

Variable hoisting

Hoisting, in JavaScript, is a way where a function or a variable can be used before its declaration.
In JavaScript, var is hoisted while the let and const does not allow hoisting, for example.

123
totalNumber = 10; console.log(totalNumber); var totalNumber;
copy

If we use the variable inside console.log() and nothing is written before it we will get an undefined value. In JavaScript first, the memory is allocated to the variable and initially, their values are undefined after this they are assigned some values.

12
console.log(company) var company="panasonic";
copy

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

¿Todo estuvo claro?

Var Tolerate Redeclaration

Var tolerates the redeclaration. If a variable is declared with the same name twice with var we will not get an error, but with let we will get an error. For instance:

12
let user = 'Mike'; let user = 'John';
copy

But we can declare variables with the same names with var and the old values of the variables are simply overwritten, for example.

123
var user = 'Mike'; var user = 'John'; console.log(user)
copy

Tarea

Declare a variable company and assign the value " Apple". Redeclare the company and now set the value “Samsung” by using the var keyword. Show the updated value on the console.

Variable hoisting

Hoisting, in JavaScript, is a way where a function or a variable can be used before its declaration.
In JavaScript, var is hoisted while the let and const does not allow hoisting, for example.

123
totalNumber = 10; console.log(totalNumber); var totalNumber;
copy

If we use the variable inside console.log() and nothing is written before it we will get an undefined value. In JavaScript first, the memory is allocated to the variable and initially, their values are undefined after this they are assigned some values.

12
console.log(company) var company="panasonic";
copy

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 5
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