Open In App

How to Declare a Variable in JavaScript ?

Variables are the heart of any programming language. In JavaScript, there are multiple ways available to declare a variable using different keywords like let, const, and var.

Example: The below code shows how you can declare variables using these keywords.




var name = "GeeksforGeeks";
console.log(name);
var name = "Virat Kohli"; // Allowed
console.log(name);
 
let desc = "A Computer Science Portal.";
// let desc = "26000 International Runs."; // Not Allowed,
// Error: Identifier 'desc' has already been declared
console.log(desc);
 
const workForce = 200;
console.log(workForce);
// const workForce; // Not Allowed,
// Error: Missing initializer in const declaration

Output
GeeksforGeeks
Virat Kohli
A Computer Science Portal.
200

Article Tags :