JavaScript Variable

A variable in JavaScript is a named container that stores a value. It can be created using the var, let, or const.

Syntax:

let variable_name = value;
const variable_name = value;

Example: In this example, age is a variable that holds a numeric value and name is a variable holding the string value.

Javascript




let age = 35;
const name = 'Kumar';
console.log("Age: " + age);
console.log("Name: " + name);


Output:

Age: 35
Name: Kumar

Difference Between Variables and Objects in JavaScript

The variables and objects are fundamental concepts but they serve different purposes. The Variables are used to store data values while objects are used to group related data and functions into a single entity.

Similar Reads

JavaScript Variable

A variable in JavaScript is a named container that stores a value. It can be created using the var, let, or const....

JavaScript Object

...

Difference between variables and object in JavaScript

An object in JavaScript is a complex data structure that groups related data together using the key-value pairs....

Contact Us