Mastering JavaScript: Unveiling Variables and Data Types ππ


Hello-world code π€ :
console.log("Hello World) ;
// console.log() prints the message to the console.
Variables in JS π¦ :
Variables store data values and can be declared using var
, let
, or const
.
var name = "HITESH";
let age = 25; // allows reassignment
const PI = 3.14; // Constant, cannot be reassigned
Data Types π’ :
JS supports two main types of data types which are classified on the basis of how they are stored and accessed in memory.
1. Primitive Data types :- (Stored by value & are immutable)
String:
"Hello, World!"
Number:
10, 3.14
Boolean:
true, false
Undefined: A variable that has been declared but not assigned a value.
Null: A special value representing "nothing".
Symbol: A unique and immutable value used as object properties.
BigInt: Used for numbers larger(like Moonβsπ distance from Earthπ).
2. Non-Primitive Data types :- (Stored by reference & are mutable)
Array:
[1, 2, 3]
Object:
{ name: "John", age: 25 }
Conclusion π :
In summary, mastering JavaScript requires understanding its core elements, like variables and data types. By learning the distinctions between primitive and non-primitive data types, we can write more efficient code. Happy coding!
Subscribe to my newsletter
Read articles from Dhruv Mittal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
