JS Tutorial



JS VARIABLES


JavaScript Variables

In JavaScript, variables are used to store data values. Think of variables as containers that hold reusable pieces of information like numbers, text, or more complex data types.

โœจ Tip: JavaScript is case-sensitive. myVar and myvar are different variables.

๐Ÿ› ๏ธ Declaring Variables

You can declare variables using var, let, or const:

// Using var
var name = "John";

// Using let
let age = 25;

// Using const (value can't change)
const country = "India";
  
  • var โ€” Old way, avoid it in modern code.
  • let โ€” Use when the value can change later.
  • const โ€” Use when the value should stay constant.

๐Ÿ“ฆ Variable Types

Variables can store different types of data:

  • String: Text inside quotes โ†’ "Hello"
  • Number: Integers or decimals โ†’ 42, 3.14
  • Boolean: true or false
  • Array: List of values โ†’ [1, 2, 3]
  • Object: Key-value pairs โ†’ {name: "John"}

๐Ÿงช Live Example:

Click the button to see JavaScript variables in action:

Output will appear here

๐Ÿง  Important Notes

  • Declare before using: Always declare variables before using them to avoid errors.
  • const is best: Prefer const unless you know the value will change.
  • Names must start with a letter, _ or $ (not numbers).
๐Ÿ“š Summary: JavaScript variables are flexible and essential. Use let and const in modern coding, and name them clearly to keep your code readable.

๐ŸŒŸ Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review