JavaScript Fundamentals: Variables, Data Types, Conversion, and Operators
Understanding Core JavaScript Concepts for Web Development

1. Why Learn JavaScript?
To build web applications (e.g., e-commerce sites, dynamic web apps).
JavaScript powers front-end (React, Angular) and back-end (Node.js) development.
2. Variable Declarations: let, const, and var
| Keyword | Scope | Reassignable? | Modern Usage |
var | Function | Yes | Avoid (legacy) |
let | Block | Yes | Preferred for variables |
const | Block | No | Preferred for constants |
Note:
let/constare block-scoped and mitigate issues withvar(e.g., global scope leaks).
3. Data Types in JavaScript
Primitive (Call by Value):
Number,String,Boolean,BigInt,Null,Undefined,Symbol.Changes affect copies, not the original.
Non-Primitive (Call by Reference):
Array,Object,Function.Changes affect the original reference.
4. Type Conversion
Explicit Conversion Examples:
let a = Number("123"); // 123 (primitive)
let b = new Number("123"); // [Number: 123] (object)
console.log(a === 123); // true
console.log(b === 123); // false (object ≠ primitive)
Coercion Rules:
Number:
"33"→33,"33abc"→NaN,true→1.Boolean:
1→true,""→false,"hitesh"→true.
String Concatenation Quirks:
javascript
Copy
Download
console.log(1 + "2"); // "12"
console.log(1 + 2 + "2"); // "32" (left-to-right evaluation)
5. Comparison Operators
Loose vs. Strict Equality:
==(loose): Converts types ("2" == 2→true).===(strict): Checks type + value ("2" === 2→false).
Null/Undefined Behaviors:
null > 0; // false (null → 0 in comparisons)
null >= 0; // true
null == 0; // false (equality treats null/undefined specially)
undefined == 0; // false
undefined always give the false
