0% found this document useful (0 votes)
4 views2 pages

JavaScript Phase1 Fundamentals

This document provides detailed notes on JavaScript fundamentals for interview preparation, covering variables, data types, type coercion, comparison operators, conditionals, loops, and functions. Key takeaways include the differences between var, let, and const, the importance of strict equality with '===', and the behavior of arrow functions. It emphasizes hoisting, scope, and how objects are compared by reference.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

JavaScript Phase1 Fundamentals

This document provides detailed notes on JavaScript fundamentals for interview preparation, covering variables, data types, type coercion, comparison operators, conditionals, loops, and functions. Key takeaways include the differences between var, let, and const, the importance of strict equality with '===', and the behavior of arrow functions. It emphasizes hoisting, scope, and how objects are compared by reference.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Interview Preparation — Phase 1: Fundamentals

Detailed Notes, Concepts & Interview Examples

1■■ Variables — var, let, const


• var is function-scoped; let and const are block-scoped.
• var can be re-declared; let/const cannot.
• Hoisting: var is hoisted with undefined; let/const are hoisted but remain in TDZ.
• const must be initialized immediately.

function test() {
if (true) {
var x = 10;
let y = 20;
const z = 30;
[Link](x, y, z);
}
[Link](x); // Works
// [Link](y); // Error
}

2■■ Data Types


• Primitive types: string, number, boolean, undefined, null, bigint, symbol.
• Reference types: object, array, function.
• typeof null === "object" (legacy bug).
• Arrays are objects; check with [Link]().

3■■ Type Coercion & Conversion


• '+' operator prefers string concatenation.
• '-', '*', '/' trigger numeric coercion.
• Boolean conversion: 0, '', null, undefined, NaN → false.
• NaN is of type 'number'.

[Link](1 + "2"); // "12"


[Link]("5" * 2); // 10
[Link]("A" - 1); // NaN

4■■ Comparison: == vs ===


• '==' performs type coercion before comparison.
• '===' checks both value and type (no coercion).
• Objects compared by reference, not value.

[Link](0 == false); // true


[Link](0 === false); // false
[Link]({} === {}); // false

5■■ Conditionals & Loops


• Falsy values: false, 0, '', null, undefined, NaN.
• for...in iterates keys; for...of iterates values.
• break exits loop; continue skips current iteration.
for (let v of [10, 20]) [Link](v); // 10, 20
for (let i in [10, 20]) [Link](i); // 0, 1

6■■ Functions
• Function Declarations are hoisted.
• Function Expressions are not hoisted.
• Arrow functions don’t have their own 'this'.
• Default and Rest parameters simplify argument handling.

function greet() { [Link]("Hi"); }


const sayHi = () => [Link]("Hello!");
function sum(...nums) { return [Link]((a, b) => a + b); }

■ Summary of Phase 1 Takeaways


• var → function-scoped; let/const → block-scoped.
• Hoisting: var undefined; let/const in TDZ.
• Use '===' for strict equality.
• Arrow functions inherit lexical 'this'.
• Objects are compared by reference.
• Always initialize const immediately.

You might also like