Basic Level:
1.What is JavaScript?
- JavaScript is a high-level, interpreted programming language used to make web pages interactive.
2.What are the data types in JavaScript?
- Primitive types: String, Number, Boolean, Null, Undefined
- Object types: Object, Array, Function
3.Explain the difference between
let, const, and var.letandconstare block-scoped, whilevaris function-scoped.constis used for constant values that shouldn't be reassigned.
4.What is the DOM?
- The Document Object Model represents the structure of a document as a tree of objects, allowing scripts to dynamically update content and style.
5.What is the difference between
== and ===?==checks for equality after type coercion, while===checks for equality without type coercion.
Intermediate Level:
- 1. Explain hoisting in JavaScript.
- Hoisting is a JavaScript behavior where variable and function declarations are moved to the top of their containing scope during compilation.
- 2.What is closure in JavaScript?
- A closure is a function that retains access to variables from its outer (enclosing) scope even after the outer function has finished executing.
- 3.What is the event loop in JavaScript?
- The event loop is the process that handles asynchronous operations by placing events in a queue and executing them in a single thread.
- 4.How does
thiskeyword work in JavaScript? thisrefers to the object it belongs to. In a function,thisrefers to the global object, but in a method, it refers to the object invoking the method.- 5.Explain the concept of promises.
- Promises are objects representing the eventual completion or failure of an asynchronous operation, providing a cleaner way to handle asynchronous code compared to callbacks.
Advanced Level:
1.What is the purpose of the
asyncandawaitkeywords?asyncis used to declare an asynchronous function, andawaitis used to wait for a Promise to resolve before continuing the execution.- 2.Explain the concept of prototypal inheritance in JavaScript.
- JavaScript uses prototype-based inheritance, where objects can inherit properties and methods from other objects through their prototype chain.
- 3.How does event delegation work?
- Event delegation is a technique where a single event listener is attached to a common ancestor, and it can manage events for multiple child elements.
- 4.What are the differences between
nullandundefined? nullis an assigned value representing the absence of an object value, whileundefinedis a variable that has been declared but not assigned a value.- 5.Explain the concept of a callback function and provide an example.
- A callback function is a function passed as an argument to another function to be executed later. Example:
setTimeout(function() { console.log("Hello, Callback!"); }, 1000);
- A callback function is a function passed as an argument to another function to be executed later. Example:
Comments
Post a Comment