Lecture
Var Keyword for Declaring Variables
var is the keyword used in JavaScript for declaring variables.
A
keywordin 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.
Lessons in this chapter ยท Getting Started with JavaScript
- 1. What is JavaScript?
- 2. What are Programming Languages?
- 3. How to Instruct a Computer
- 4. Comment
- 5. Multiple-choice quiz
- 6. Data Types
- 7. Variable Declaration Keyword - var
- 8. Scope
- 9. Variable Declaration Keyword - let
- 10. Constant
- 11. Operators
- 12. Variable Assignment
- 13. Identifiers and Literals
- 14. Fill-in-the-blank quiz
Quiz
0 / 1
Variables declared with the var keyword cannot be reassigned.
True
False
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help