Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Value = undefined

In computer programs, variables are frequently declared without an initial value. This value might be a result of a calculation or an input provided later, such as user input.

A variable declared without an assigned value will default to undefined.

Following the execution of this statement, the variable carName will hold the value undefined:

Example

let carName;

Re-Declaring JavaScript Variables

When you re-declare a JavaScript variable that was initially declared with var, it retains its value.

Following the execution of these statements, the variable carName will maintain the value “Volvo”:

Example

var carName = “Volvo”;
var carName;

Note

Attempting to re-declare a variable that was originally declared with let or const is not permissible.

The following operation will not succeed:

let carName = “Volvo”;
let carName;