Javascript Interview Deck 5 Flashcards
What is JavaScript?
JavaScript is a high-level, interpreted programming language primarily used for client-side web development. It enables interactive web pages and is commonly used in conjunction with HTML and CSS.
What are the data types in JavaScript?
JavaScript has several built-in data types, including:
Primitive types: string, number, boolean, null, undefined, symbol.
Non-primitive types: object (including arrays and functions).
Explain the concept of hoisting in JavaScript.
Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their containing scope during compilation, regardless of where they are declared.
What is the difference between == and === in JavaScript?
== is used for loose equality comparison, where type conversion is performed, while === is used for strict equality comparison, where both value and type must be the same.
Explain the event bubbling and event capturing in JavaScript.
Event bubbling is a propagation mechanism in the DOM where events are first captured by the innermost element and then propagated to outer elements. Event capturing is the reverse, where events are captured at the outermost element and then propagated to inner elements.
What are closures in JavaScript?
Closures are functions that have access to the outer (enclosing) function’s variables, even after the outer function has finished executing. They “remember” the environment in which they were created.
What are promises in JavaScript?
Promises are a way to handle asynchronous operations in JavaScript. They represent a value that may be available now, or in the future, or never. Promises allow chaining asynchronous operations and handling success or failure with then() and catch() methods.
What are arrow functions in JavaScript?
Arrow functions are a concise way to write anonymous functions in JavaScript. They have a shorter syntax compared to traditional function expressions and do not bind their own this, arguments, super, or new.target.
What is the difference between let, const, and var?
let and const were introduced in ES6 (ECMAScript 2015) for declaring variables. let allows reassignment of the variable’s value, while const does not allow reassignment once a value is assigned. var is the pre-ES6 way of declaring variables and has function scope rather than block scope.
Explain the concept of AJAX.
AJAX (Asynchronous JavaScript and XML) is a technique used in web development for creating dynamic web pages that can update content without reloading the entire page. It involves making asynchronous requests to the server using JavaScript and handling the server’s response dynamically.
`
Explain closures in JavaScript.
Closures are inner functions that have access to the outer (enclosing) function’s variables. They “remember” the environment in which they were created, even after the outer function has finished executing. Closures are commonly used for data encapsulation and maintaining state in JavaScript.
What is hoisting in JavaScript?
Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their containing scope during compilation. This allows variables and functions to be used before they are declared. However, only the declarations are hoisted, not the initializations.
What is the event loop in JavaScript?
The event loop is the mechanism in JavaScript responsible for handling asynchronous operations. It continuously checks the call stack for any function that needs to be executed and the callback queue for any asynchronous tasks. It ensures that the call stack is never blocked, allowing non-blocking asynchronous behavior in JavaScript.
How can you handle errors in JavaScript?
Errors in JavaScript can be handled using try-catch blocks. Code that may throw an error is placed within the try block, and if an error occurs, it is caught in the catch block. This allows graceful error handling and prevents the script from crashing.
Explain the concept of callback functions.
Callback functions are functions that are passed as arguments to other functions and are executed after a specific task is completed. They are commonly used in asynchronous programming to handle asynchronous operations such as AJAX requests, event handling, and timeouts.