Declaring Variables in a Single Line
You can declare multiple variables in a single line using the var, let, or const keyword followed by a comma-separated list of variable names.
Syntax:
let x = 20, y = 30, z = 40;
Example: In this example, we are defining the three variables at once.
Javascript
let x = 20, y = 'G' , z = "w3wiki" ; console.log( "x: " , x, "\ny: " , y, "\nz: " , z); |
Output
x: 20 y: G z: w3wiki
How to declare multiple Variables in JavaScript?
In this article, we will see how to declare multiple Variables in JavaScript. The variables can be declared using var, let, and const keywords. Variables are containers that store some value and they can be of any type.
These are the following ways to declare multiple variables:
Table of Content
- Declaring Variables Individually
- Declaring Variables in a Single Line
- Using Destructuring Assignment
Contact Us