VARIABLES

What are Variables?

In JavaScript, variables are used to store data. They are an essential part of any programming language, as they allow you to store, retrieve, and manipulate data in your programs.

There are a few different ways to declare variables in JavaScript, each with its own syntax and rules. In this blog post, we'll take a look at the different types of variables available in JavaScript and how to use them.

Variable Declaration

To declare a variable in JavaScript, you use the "var" , "let" or "const" keyword followed by the name of the variable. For example:

app/page.tsx
1var x = 5;
2let y = "Hello";
3const z = true;

Data types

JavaScript has several data types, including numbers, strings, booleans, null, and undefined. You can use the typeof operator to check the data type of a variable. For example:

app/page.tsx
1typeof 42; // "number"
2typeof "hello"; // "string"
3typeof true; // "boolean"
4typeof null; // "object" (this is a quirk of JavaScript)
5typeof undefined; // "undefined"

Tip : JavaScript is dynamically typed language ,so type checking takes place at runtime or execution time.