Category: react
Variables in javascript
Published on 23 Jun 2026
Explanation
Variables are used to store data
in JavaScript. The keywords var, let,
and const are used to declare
variables. Modern JavaScript
primarily uses let
and const.
Code:
let name = 'Praveen'; const company = 'HackForge Academy'; console.log(name, company);
Explanation
JavaScript supports several primitive
data types
including String, Number, Boolean,
Undefined, Null,
and BigInt.
Code:
let username = 'John'; let age = 25; let isActive = true; let city; let salary = null;
Explanation
The typeof operator is used to
determine the data type of a
variable at runtime.
Code:
console.log(typeof 'Hello'); console.log(typeof 100); console.log(typeof true);
Explanation
JavaScript also supports complex data types
such as Objects and Arrays, which
can store collections of related data.
Code:
const student = {
name: 'John',
age: 22
};
const skills = ['HTML', 'CSS', 'JavaScript'];
Explanation
Variables can be updated when declared
with let, while const variables cannot
be reassigned after initialization.
Code:
let score = 50; score = 75; const country = 'India'; // country = 'USA'; // Error