Lecture

Var Keyword for Declaring Variables

var is the keyword used in JavaScript for declaring variables.

A keyword in programming languages is a word that carries special meaning and is used for defining variables or functions.

A variable is a named storage space that can store data for later reference or modification.

var provides a space to store a specific value and retrieve it when necessary.


How to Use the var Keyword

To declare a variable, use the var keyword, specify the variable name, and assign a value.

Declaring a var variable
var studentName = 'Alex';

Here, studentName is the name of the variable, and "Alex" is the value stored in that variable.


Characteristics of Variables Defined with var

A var variable, once declared, can be reassigned to hold a different value.

Variable reassignment
var number = 10; number = 20; // The value of variable number is changed to 20.
Mission
0 / 1

Variables declared with the var keyword cannot be reassigned.

True
False

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help

Code Editor

Run

Execution Result