Java-Script Reference

Links : Learn     Interview Questions     IDE
            

JavaScript Interview Questions - Page 3

< Previous Page              Next Page >
Question: What are the advantages of using strict mode in JavaScript?
Answer: The strict mode is a feature in JavaScript that helps catch common coding mistakes and "unsafe" actions. It enforces stricter parsing and error handling, disables features that are confusing or poorly thought out, and prevents the use of undeclared variables.

Question: What is the this keyword in JavaScript?
Answer: The 'this' keyword refers to the object that owns the code being executed. Its value is determined by how a function is called. In the global scope or inside a function not in strict mode, this refers to the global object (e.g., window in a web browser).

In methods, this refers to the object that is invoking the method.

Question: Can you explain the concept of hoisting in JavaScript?
Answer: InJavaScript hoisting is a mechanism where variables and function declarations are moved to the top of their containing scope during the compilation phase. However, only the declarations are hoisted, not the initializations.

This means you can use a variable or call a function before it's declared, but the value will be undefined until the assignment is encountered.

Question: Can you explain the concept of scope chain in JavaScript?
Answer: The scope chain refers to the hierarchy of scopes in which variables and functions are defined and can be accessed. When a variable or function is referenced, JavaScript first searches the current scope for the identifier. If it's not found, it looks in the outer scope, and so on until it reaches the global scope.

Question: What are the differences between 'setTimeout()' and 'setInterval()'?
Answer: Both 'setTimeout()' and 'setInterval()' are functions used to execute code asynchronously after a specified delay. However, 'setTimeout()' executes the code once after the specified delay, while 'setInterval()' repeatedly executes the code at specified intervals until it's cleared using 'clearInterval()'.

Question: What is a higher-order function in JavaScript?
Answer: A higher-order function is a function that either takes one or more functions as arguments or returns a function as its result.

Question: What is a JavaScript Promise?
Answer: A Promise is an object representing the eventual completion or failure of an asynchronous operation and its resulting value.

Question: How can one handle errors in JavaScript?
Answer: Errors in JavaScript can be handled using 'try...catch' blocks.
• The code that may potentially throw an error is placed inside the try block.
• If an error occurs, it's caught by the catch block where you can handle it gracefully.

Question: How do you check if a variable is an array in JavaScript?
Answer: One can use the Array.isArray() method to check if a variable is an array.

< Previous Page Next Page >