How to Declare Multiple Variables in JavaScript? Last Updated : 25 Oct, 2024 Comments Improve Suggest changes Like Article Like Report JavaScript variables are used as container to store values, and they can be of any data type. You can declare variables using the var, let, or const keywords. JavaScript provides different ways to declare multiple variables either individually or in a single line for efficiency and readability.Declaring Multiple Variables IndividuallyThe most simple way to declare variables is to declare them one by one using var, let, or const keyword. You can directly assign values and can access them using the variable name. Syntaxlet x = 20;let y = 30;let z = 40;Example: Declaring three different variables using let keyword. JavaScript let x = 20; let y = 'G'; let z = "GeeksforGeeks"; console.log("x: ", x); console.log("y: ", y); console.log("z: ", z); Outputx: 20 y: G z: GeeksforGeeks Table of ContentDeclaring Variables IndividuallyDeclaring Variables in a Single LineUsing Destructuring AssignmentDeclaring Multiple Variables in a Single LineYou can declare multiple variables in one line using a comma-separated list with var, let, or const keyword. This approach can make the code more concise.Syntaxlet x = 20, y = 30, z = 40;Example: Declaring and assigning three different variables at once. JavaScript let x = 20, y = 'G', z = "GeeksforGeeks"; console.log("x: ", x); console.log("y: ", y); console.log("z: ", z); Outputx: 20 y: G z: GeeksforGeeks Using Destructuring AssignmentDestructuring assignment is a modern feature in JavaScript that allows you to unpack values from arrays or properties from objects into distinct variables in a single line. This is especially useful when dealing with arrays or objects.Syntaxconst [var1, var2, var3] = [val1, val2, val3];Example: Declaring three different variables by destructuring them at once. JavaScript const [x, y, z] = [20, 'G', "GeeksforGeeks"]; console.log("x: ", x); console.log("y: ", y); console.log("z: ", z); Outputx: 20 y: G z: GeeksforGeeks Comment More infoAdvertise with us Next Article How to Declare Multiple Variables in JavaScript? V vkash8574 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to declare Global Variables in JavaScript ? Global Variables Global variables in JavaScript are variables declared outside of any function. These variables are accessible from anywhere within the script, including inside functions. Global variables are declared at the start of the block(top of the program)Var keyword is used to declare variab 2 min read How to create Static Variables in JavaScript ? To create a static variable in JavaScript, you can use a closure or a function scope to encapsulate the variable within a function. This way, the variable maintains its state across multiple invocations of the function. Static keyword in JavaScript: The static keyword is used to define a static meth 2 min read How to create a private variable in JavaScript ? In this article, we will try to understand how we could create private variables in JavaScript. Let us first understand what are the ways through which we may declare the variables generally in JavaScript. Syntax: By using the following syntaxes we could declare our variables in JavaScript. var vari 3 min read How to Create a String with Variables in JavaScript? To create a string with variables in JavaScript, you can use several methods, including string concatenation, template literals, and the String methods. Here are the common approaches:1. Template Literals (Recommended)Template literals are the modern and most preferred way to create strings with var 2 min read How to declare namespace in JavaScript ? The coding standard of assigning scope to identifiers (names of types, functions, variables, and so on) to avoid conflicts between them is known as a namespace. It is a framework for a collection of identifiers, functions, and methods. It gives its contents a sense of direction so that they are easi 3 min read How to Pass variables to JavaScript in Express JS ? Express is a lightweight framework that sits on top of Node.jsâs web server functionality to simplify its APIs and add helpful new features. It makes it easier to organize your applicationâs functionality with middleware and routing. When working with Express.js you may encounter scenarios where you 2 min read How to declare variables in different ways in JavaScript? In JavaScript, variables can be declared using keywords like var, let, or const, each keyword is used in some specific conditions. Understanding these declarations is crucial for managing variable lifetimes and avoiding unintended side effects in code.Table of Content JavaScript varJavaScript letJav 2 min read How to Use Dynamic Variable Names in JavaScript? Dynamic variable names are variable names that are not predefined but are generated dynamically during the execution of a program. This means the name of a variable can be determined at runtime, rather than being explicitly written in the code.Here are different ways to use dynamic variables in Java 2 min read How to Declare Variables in TypeScript ? In TypeScript, a variable can be defined by specifying the data type of the value it is going to store. It will store the values of the specified data type only and throws an error if you try to store the value of any other data type. You can use the colon syntax(:) to declare a typed variable in Ty 2 min read How to pass value to execute multiple conditions in JavaScript ? In this article, we will try to understand how we can pass certain values in multiple conditions in JavaScript with the help of certain coding examples. The term, multiple conditionals, actually refer to more than one conditionals in number. This would eventually include the usage of "if-elseif-else 3 min read Like