Variables & Types (Q1–Q4)

1. What's the difference between var, let, and const? ⭐

  • var is function-scoped and hoisted.

  • let is block-scoped and can be reassigned.

  • const is block-scoped and cannot be reassigned.

    Advertisement

Modern JavaScript recommends using const by default, let only when reassignment is required, and avoiding var in new code.

Learn More: Variables & Data Types


2. Does const make an object immutable?

No.

const prevents the variable from being reassigned, but the object's properties can still be modified.

Learn More: Variables & Data Types


3. What's the difference between == and ===?

  • == performs comparison after type coercion.

  • === compares both value and data type.

For predictable and reliable code, always prefer strict equality (===).

Learn More: Variables & Data Types


4. What's the difference between null and undefined?

  • undefined means a variable has been declared but has not been assigned a value.

  • null represents an intentional assignment indicating the absence of a value.

Learn More: Variables & Data Types


Functions (Q5–Q7)

5. What's the difference between a function declaration and an arrow function?

Function declarations are hoisted and create their own this context.

Arrow functions are shorter, are not hoisted in the same way, and inherit this from their surrounding scope.

Learn More: Functions


6. What is a callback function?

A callback is a function passed as an argument to another function so it can be executed later.

Callbacks were the primary mechanism for handling asynchronous operations before Promises were introduced.

Learn More: Functions


7. What are default and rest parameters?

  • Default Parameters assign fallback values when arguments are not supplied.

  • Rest Parameters (...args) collect multiple remaining arguments into a single array.

Both features simplify function design and improve flexibility.

Learn More: Functions


Arrays & Objects (Q8–Q11)

8. What's the difference between map(), filter(), and forEach()? ⭐

  • map() creates and returns a transformed array.

  • filter() returns only the elements matching a condition.

  • forEach() simply iterates over elements and does not return a new array.

These are among the most frequently used array methods in modern JavaScript.

Learn More: Arrays & Objects


9. How do you find an element in an array?

Common methods include:

  • find() – Returns the first matching element.

  • includes() – Returns true or false.

  • indexOf() – Returns the position of the element.

Choose the method based on whether you need the value, a Boolean result, or the index.

Learn More: Arrays & Objects


10. What is destructuring?

Destructuring extracts values from objects or arrays into variables using concise syntax.

Example:

const { id, name } = user;

It is widely used when working with API responses, Playwright, and modern JavaScript applications.

Learn More: Arrays & Objects


11. What's the difference between JSON and a JavaScript object?

  • JSON is a text-based data format used for storing and transferring information.

  • JavaScript Objects are live in-memory objects used by applications.

Conversion methods:

  • JSON.parse() converts JSON into an object.

  • JSON.stringify() converts an object into JSON.

Learn More: Arrays & Objects


Async JavaScript (Q12–Q15)

12. What is a Promise?

A Promise represents the eventual completion or failure of an asynchronous operation.

A Promise can be in one of three states:

  • Pending

  • Fulfilled

  • Rejected

Promises are commonly handled using .then() and .catch().

Learn More: Promises & Async/Await


13. What is async/await? ⭐

async/await provides a cleaner way to write Promise-based asynchronous code.

The await keyword pauses execution until the Promise completes, making asynchronous code easier to read and maintain.

It is extensively used in Playwright, API automation, and modern JavaScript applications.

Learn More: Promises & Async/Await


14. How do you handle errors with async/await?

Use a try...catch block.

This is the recommended approach for catching exceptions from asynchronous operations and is equivalent to using .catch() with Promises.

Learn More: Promises & Async/Await


15. Why is asynchronous programming important in test automation?

Most browser interactions, API requests, and network operations are asynchronous.

Failing to use await correctly may cause assertions to execute before an action has completed, resulting in unstable or flaky automation tests.

Understanding asynchronous programming is therefore essential for reliable Playwright and API automation.

Learn More: JavaScript for Automation

Next Steps