Data types in Javascript:
JavaScript data types define what kind of values a variable can hold and how those values behave in a program.

Primitive Data Type
- Primitive data types in JavaScript represent simple, immutable values stored directly in memory, ensuring efficiency in both memory usage and performance.
- Number,String,BigInt,boolean,Null,Symbol,Undefined
Non-Primitive data type
Also known as reference types.
- Object – Stores data in key-value pairs.
- Array – Stores multiple values in a single variable.
- Function – A reusable block of code.
Variables in JavaScript
A variable is a container used to store data in JavaScript.
Let's understand the following statement:
age = 25;
- age → Identifier (variable name)
- = → Assignment operator
- 25 → Value In JavaScript, we can declare variables using three keywords:
- var
- let
- const
var
The var keyword allows us to redeclare and reassign a variable.
var age = 25; var age = 30; console.log(age); // 30 Here, the variable is declared again with a new value.
Although var is supported in JavaScript, it is generally better to use let and const because they provide block scope.
let
The let keyword allows us to change the value of a variable, but it does not allow redeclaration in the same scope.
let age = 25;
age = 35;
console.log(age); // 35
We can update the existing value using let.
However, this will produce an error:
let age = 25; let age = 35; // SyntaxError const
The const keyword is used when we don't want to reassign a variable.
const age = 25; console.log(age); // 25
We cannot assign another value to the same variable.
const age = 25; age = 30; // TypeError We also cannot redeclare a const variable in the same scope.
Difference between var, let and const
| Keyword | Redeclaration | Reassignment |
|---|---|---|
| var | Yes | Yes |
| let | No | Yes |
| const | No | No |
Arithmetic Operators
Arithmetic operators are used to perform mathematical calculations.
console.log(10 + 5); // 15 console.log(10 - 5); // 5 console.log(10 * 5); // 50 console.log(10 / 5); // 2 console.log(10 % 3); // 1 console.log(2 ** 3); // 8 Implicit Type Conversion
One thing I found interesting while learning JavaScript is that it automatically converts data types in some situations.
This is called implicit type conversion or type coercion.
Let's look at a few examples.
console.log(10 + 5); // 15 console.log(10 + '5'); // 105 console.log(10 - '5'); // 5 console.log(10 * '5'); // 50 console.log(10 / '5'); // 2 When we use 10 + '5', JavaScript treats the operation as string concatenation and gives 105.
But when we use subtraction, multiplication, or division, JavaScript converts the string '5' into a number.
Another example:
let result = 'Ramayanam' - 2; console.log(result); // NaN Here, the result is NaN, which means Not-a-Number.
This happens because JavaScript cannot convert 'Ramayanam' into a valid number for subtraction.
Increment and Decrement Operators
Increment (++)
let i = 5; i++; console.log(i); // 6 Decrement (--)
let i = 5; i--; console.log(i); // 4 There are two ways to use the increment operator: pre-increment and post-increment.
Post-increment (i++)
First, it uses the current value. Then it increases the value by one.
let i = 1; console.log(i++); // 1 console.log(i); // 2 Pre-increment (++i)
First, it increases the value. Then it returns the updated value.
let i = 1; console.log(++i); // 2 console.log(i); // 2 At first, I found these two a little confusing. But after practising with examples, the difference became easier to understand.
A Small Exercise with Increment and Decrement
Here is one expression that I practised:
let i = 1; let j = 5; let result = ++i + i + 1 + j-- - --i; console.log(i, j, result); Output: 1 4 9 Let's break it down:
- ++i increases i to 2.
- i gives the current value 2.
- 1 remains 1.
- j-- uses 5 first, then decreases j to 4.
- --i decreases i to 1. Final calculation:
2 + 2 + 1 + 5 - 1 = 9
This exercise helped me understand how JavaScript evaluates pre-increment and post-increment expressions.
Logical Operators
Logical operators are used when we want to check multiple conditions.
JavaScript has three main logical operators:
- AND (&&)
- OR (||)
- NOT (!)
AND (&&)
Both conditions must be true to get a true result.
let ram = 16; let rom = 512; console.log(ram >= 16 && rom >= 1000); Output: false The first condition is true, but the second condition is false. So the final result is false.
OR (||)
At least one condition must be true.
let ram = 16; let rom = 512; console.log(ram >= 16 || rom >= 1000); Output: true The first condition is true, so the final result is true.
NOT (!)
The NOT operator reverses the Boolean value.
console.log(!true); // false console.log(!false); // true Conditional Statements (if-else)
Finally, I learned about conditional statements.
We use if-else when we want to execute different code depending on whether a condition is true or false.
For example, let's check whether a person is eligible to vote.
let age = 19; if (age >= 18) { console.log('Eligible'); } else { console.log('Not Eligible'); } Output: Eligible Since the age is 19, the condition age >= 18 is true, so the if block executes.
We can use the same concept in login validation, registration forms, and many other real-world applications.
References

