Learn
Variables
Create a Variable: var
To create a variable using var
, we use the following syntax:
Variable Naming Rules:
- Variable names must start with a letter, underscore, or dollar sign.
- They can contain letters, numbers, underscores, or dollar signs.
- They are case-sensitive, so
myVariable
andmyvariable
are different variables.
Assigning a Value to a Variable
We can assign a value to a variable during declaration or later in the code. Example:
Variable usage
Once we have assigned a value to a variable, we can use it in our code. Example:
Instructions
1.
Declare a new variable called name
and assign it the value of "John"
.
2.
Print the value of the name
variable to the console.
3.
Declare another variable called numOfPets
and assign it the value of 3
.
4.
Print the value of the numOfPets
variable to the console.
Sign up to start coding
Already have an account?
Sign In
Course content