JavaScript Interview Prep7 min Read

Placement Prep 2026: Master 10 JavaScript Quirks for TCS NQT, Infosys SP & Google India SDE-1

By DevLingo Team • Published

Namaste future coding rockstars! Navigating the world of web development can be thrilling, especially with the booming tech scene in Bangalore and Hyderabad offering ₹12LPA+ opportunities. As you gear up for top-tier placements like TCS NQT, Infosys SP, or even aiming for Google India SDE-1, mastering JavaScript isn't just about syntax – it's about understanding its soul, quirks and all.

At DevLingo, India's premier gamified coding app, we believe true mastery comes from understanding the 'why' behind the 'what'. JavaScript, while incredibly powerful, has a reputation for surprising even experienced developers. Many of its so-called 'quirks' aren't bugs; they're features behaving exactly as per their underlying rules. Understanding these rules is your secret weapon for nailing those technical interviews and building robust applications.

Forget rote learning! Let's dive deep into 10 JavaScript behaviors that might look weird until you understand their fundamental logic. Get ready to elevate your coding game!

1. The Curious Case of `typeof null`

**The Weirdness:** Log `typeof null` in your console, and you'll get `'object'`. Wait, `null` is a primitive value, not an object. Why?

**The Rule:** This is a well-known, long-standing bug in JavaScript since its inception. Brendan Eich, JS's creator, acknowledged it, but fixing it would break countless existing websites and libraries, so it remains. When implementing `typeof`, `null` was represented internally as `000`, and `object` type tags also started with `000`. It was an oversight.

**Code Example:** ```javascript console.log(typeof null); // Output: "object" ```

**Interview Relevance:** Often asked to test your historical knowledge and attention to detail. Don't be fooled; `null` *is* a primitive type.

2. `NaN` Is Never Equal to Itself

**The Weirdness:** `NaN` stands for "Not a Number." If you compare `NaN === NaN`, it returns `false`. How can a value not be equal to itself?

**The Rule:** `NaN` represents an undefined or unrepresentable numeric value (e.g., `0/0` or `Math.sqrt(-1)`). The IEEE 754 floating-point standard dictates that `NaN` is unique and non-equivalent to *any* value, including other `NaN`s. To check if a value is `NaN`, use `Number.isNaN()` (stricter) or the global `isNaN()` (less strict, coerces values).

**Code Example:** ```javascript console.log(NaN === NaN); // Output: false console.log(Number.isNaN(NaN)); // Output: true console.log(Number.isNaN(0/0)); // Output: true console.log(isNaN('hello')); // Output: true (coerces 'hello' to NaN) console.log(Number.isNaN('hello')); // Output: false (no coercion) ```

**Interview Relevance:** A classic trick question. Demonstrates understanding of floating-point intricacies and correct `NaN` checking methods.

3. Type Coercion: The `+` vs. `-` Operator

**The Weirdness:** `'5' + 1` results in `'51'`, but `'5' - 1` results in `4`. Why the different behavior for similar operators?

**The Rule:** The `+` operator is overloaded. If *either* operand is a string, it performs string concatenation. If both are numbers, it performs addition. The `-` operator, however, *only* performs numeric subtraction. When it encounters a string, it attempts to coerce the string into a number. If successful, it subtracts; otherwise, it results in `NaN`.

**Code Example:** ```javascript console.log('5' + 1); // Output: "51" (string concatenation) console.log('5' - 1); // Output: 4 (string '5' coerced to number 5) console.log('hello' - 1); // Output: NaN ```

**Interview Relevance:** Crucial for understanding how JavaScript handles different data types, especially when dealing with user input from forms (which are often strings).

4. Floating Point Precision (`0.1 + 0.2`)

**The Weirdness:** Open your console and type `0.1 + 0.2`. You might expect `0.3`, but you'll often see `0.30000000000000004`.

**The Rule:** JavaScript, like many other languages, uses the IEEE 754 standard for floating-point arithmetic. This standard represents numbers in binary, and just as `1/3` cannot be perfectly represented in decimal (`0.333...`), some decimal fractions (like `0.1`, `0.2`) cannot be perfectly represented in binary. This leads to tiny precision errors.

**Code Example:** ```javascript console.log(0.1 + 0.2); // Output: 0.30000000000000004 console.log(0.1 + 0.2 === 0.3); // Output: false ```

**Interview Relevance:** Highlights awareness of numeric precision issues, especially important for financial calculations. Always use rounding methods or libraries for precise decimal arithmetic.

5. Hoisting: `var` vs. `let`/`const` and the Temporal Dead Zone

**The Weirdness:** ```javascript console.log(myVar); // undefined var myVar = 10;

console.log(myLet); // ReferenceError let myLet = 20; ``` Why does `myVar` not throw an error, but `myLet` does?

**The Rule:** JavaScript 'hoists' declarations to the top of their scope during compilation. `var` declarations are hoisted *and initialized* to `undefined`. `let` and `const` declarations are also hoisted, but they are *not initialized* and remain in a 'Temporal Dead Zone' (TDZ) until their declaration is encountered during execution. Accessing them in the TDZ throws a `ReferenceError`.

**Code Example:** ```javascript // 'var' hoisting console.log(a); // undefined var a = 5; console.log(a); // 5

// 'let'/'const' and TDZ // console.log(b); // ReferenceError: Cannot access 'b' before initialization let b = 10; console.log(b); // 10 ```

**Interview Relevance:** A fundamental concept for modern JavaScript. Demonstrates understanding of scope, variable lifecycle, and why `let`/`const` are generally preferred to `var`.

6. The Shifting Sands of `this`

**The Weirdness:** The value of the `this` keyword can seemingly change depending on how a function is called, leading to confusion.

**The Rule:** The `this` keyword's value is determined by how the function is invoked, not where it's defined. Here are common scenarios: - **Global context:** `this` refers to the global object (`window` in browsers, `global` in Node.js). - **Method invocation:** `this` refers to the object the method is called on. - **Function invocation (strict mode):** `this` is `undefined`. - **Constructor invocation:** `this` refers to the new instance. - **Arrow functions:** `this` lexically binds to the `this` of its enclosing scope (it doesn't have its own `this`).

**Code Example:** ```javascript const obj = { name: 'DevLingo', greet: function() { console.log(`Hello from ${this.name}`); }, greetArrow: () => { console.log(`Hello from ${this.name}`); // 'this' here refers to global/window } };

obj.greet(); // Output: Hello from DevLingo (this is obj) const standAloneGreet = obj.greet; standAloneGreet(); // Output: Hello from undefined (this is global/window, if not in strict mode) obj.greetArrow(); // Output: Hello from undefined (depends on global 'name' or undefined)

// Example using .call(), .apply(), .bind() to control 'this' const anotherObj = { name: 'Coder' }; obj.greet.call(anotherObj); // Output: Hello from Coder ```

**Interview Relevance:** Mastering `this` is crucial for object-oriented JavaScript, event handling, and using methods like `call`, `apply`, `bind` – frequently tested concepts.

7. Automatic Semicolon Insertion (ASI)

**The Weirdness:** You can often write JavaScript code without semicolons, and it works fine. Then, sometimes, omitting one leads to unexpected errors.

**The Rule:** JavaScript has a mechanism called Automatic Semicolon Insertion (ASI). If it encounters a newline where a semicolon *could* legally end a statement, it *might* insert one. However, this is a heuristic and doesn't always work as expected, especially in cases like `return` statements or complex expressions, leading to bugs that are hard to debug. Always using semicolons (or linting rules that enforce them consistently) is best practice.

**Code Example:** ```javascript function getResult() { return { value: 42 } } // ASI inserts semicolon after 'return', returning 'undefined'

console.log(getResult()); // Output: undefined

// Correct way: function getCorrectResult() { return { value: 42 }; } console.log(getCorrectResult()); // Output: { value: 42 } ```

**Interview Relevance:** Tests your understanding of JavaScript's parsing behavior and adherence to best practices for code readability and error prevention.

8. The Great Equality Debate: `==` vs. `===`

**The Weirdness:** `'' == 0` is `true`, but `'' === 0` is `false`. Similarly, `null == undefined` is `true`, but `null === undefined` is `false`.

**The Rule:** - `==` (loose equality) performs type coercion before comparison. If the types are different, JavaScript attempts to convert one or both operands to a common type before comparing their values. - `===` (strict equality) compares both the value and the type without any type coercion. If the types are different, it immediately returns `false`.

**Code Example:** ```javascript console.log(false == 0); // Output: true (boolean coerced to number) console.log(false === 0); // Output: false (different types) console.log('5' == 5); // Output: true (string coerced to number) console.log('5' === 5); // Output: false (different types) console.log(null == undefined); // Output: true (special case, both represent absence of value) console.log(null === undefined); // Output: false (different types) ```

**Interview Relevance:** A fundamental concept for avoiding subtle bugs. Strict equality (`===`) is almost always preferred to prevent unexpected type coercion issues, making your code more predictable.

9. Array `sort()` Default Behavior

**The Weirdness:** If you try to sort an array of numbers like `[1, 10, 2]`, you might expect `[1, 2, 10]`. But `[1, 10, 2].sort()` often yields `[1, 10, 2]` or `[1, 2, 10]` depending on engine (it should be `[1, 10, 2]`).

**The Rule:** By default, the `Array.prototype.sort()` method converts all elements to strings and then sorts them lexicographically (based on their Unicode code points). For numerical sorting, you *must* provide a `compareFunction`.

**Code Example:** ```javascript const numbers = [1, 10, 2, 21]; console.log(numbers.sort()); // Output: [1, 10, 2, 21] (Incorrect for numeric sort)

// Correct numeric sort: numbers.sort((a, b) => a - b); // Ascending console.log(numbers); // Output: [1, 2, 10, 21]

numbers.sort((a, b) => b - a); // Descending console.log(numbers); // Output: [21, 10, 2, 1] ```

**Interview Relevance:** A common pitfall in coding challenges. Shows your attention to detail regarding built-in method behaviors and knowing when to customize them.

10. `parseInt()` and Radix

**The Weirdness:** `parseInt('08')` can return `8` in modern browsers/strict mode, but `0` in older environments. `parseInt('0xF')` returns `15`.

**The Rule:** `parseInt()` parses a string argument and returns an integer. Its second argument, `radix` (the base, e.g., 10 for decimal, 16 for hexadecimal), is crucial. If omitted, JavaScript tries to guess the radix: it defaults to 10 unless the string starts with `0x` (then 16) or, in older engines/non-strict mode, `0` (then 8, octal). Always explicitly provide the `radix` (usually 10) to prevent unexpected behavior.

**Code Example:** ```javascript console.log(parseInt('10', 10)); // Output: 10 (decimal) console.log(parseInt('010')); // Output: 10 (modern JS, defaults to 10) console.log(parseInt('010', 8)); // Output: 8 (octal 010 is 8 in decimal) console.log(parseInt('0xF', 16)); // Output: 15 (hexadecimal) console.log(parseInt('F', 16)); // Output: 15 (hexadecimal) console.log(parseInt('abc')); // Output: NaN ```

**Interview Relevance:** Crucial when parsing string-based numerical input, especially from user forms or APIs. Demonstrates defensive programming and understanding of type conversion.

Master JavaScript, Master Your Placements!

Understanding these 'weird' JavaScript behaviors isn't just about memorizing facts; it's about grasping the underlying design principles that make the language tick. This depth of knowledge is what differentiates a good coder from a great one – exactly what top companies like TCS, Infosys, and Google look for in SDE-1 roles.

Don't let these quirks catch you off guard in your next interview for that dream job at a high-growth Bangalore or Hyderabad startup with a ₹12LPA+ package. Practice them, experiment with them, and integrate them into your problem-solving toolkit.

Ready to turn these challenges into strengths? Join DevLingo today and gamify your journey to becoming a JavaScript maestro. Our interactive platform helps you solidify these concepts through challenges, quizzes, and real-world coding scenarios. Your placement prep for 2026 starts now!

Frequently Asked Questions

How do these JavaScript quirks typically appear in coding interviews?

These quirks are commonly tested in multiple-choice questions, 'find the output' problems, or as part of debugging scenarios. Interviewers use them to gauge your understanding of JavaScript's fundamental behavior, not just syntax. For instance, you might be asked to predict the output of `0.1 + 0.2 === 0.3` or explain why `typeof null` is 'object'. For roles targeting TCS NQT, Infosys SP, or Google India SDE-1, expect questions that require you to apply this knowledge to practical coding problems or explain specific behaviors during a live coding session.

What's the most common mistake freshers make when encountering these JavaScript behaviors?

The most common mistake freshers make is assuming JavaScript will always behave like other programming languages they've learned, especially regarding type handling and equality. They often rely on intuition rather than understanding JavaScript's specific rules for type coercion (`==`), `this` context, or how built-in functions like `sort()` and `parseInt()` work by default. Forgetting to provide a `radix` to `parseInt()` or a `compareFunction` to `Array.prototype.sort()` are frequent errors. The key is to avoid guessing and explicitly understand the documented behavior, which is critical for securing roles in demanding Bangalore/Hyderabad startups.

🦊

Ready to stop scrolling and start coding?

Everything you just read is built into DevLingo as a playable challenge. Don't just learn it. **Own it.**

Download QR
Scan to Download