In JavaScript, variables are used to store data values. You can declare a variable using the var
,
let
, or const
keywords.
// Using var
var name = "John";
// Using let
let age = 30;
// Using const
const pi = 3.14;
myVar
and myvar
are different).
var firstName = "Alice";
let lastName = "Smith";
const birthYear = 1990;
console.log(firstName + " " + lastName + " was born in " + birthYear);
This code declares three variables and logs a message to the console.
Open the browser console (F12) to see the output of the example code.