JavaScript Interview Questions (Part3)
Why extending array is a bad idea?
Extending built-in objects like arrays by adding methods to their prototypes can lead to unexpected behavior and compatibility issues with other code or libraries. It's better to create utility functions that operate on arrays instead of modifying their prototypes directly.
How do you check if an object is an array or not?
You can use the Array.isArray() method to check if an object is an array. For example: Array.isArray(myObject) returns true if myObject is an array.
Can you assign an anonymous function to a variable?
Yes, you can assign an anonymous function (also known as a function expression) to a variable. For example: const myFunction = function() { /* function body */ };
Difference between private, public, and static variables?
In object-oriented programming, private variables are only accessible within the class, public variables can be accessed from outside the class, and static variables are shared among all instances of the class, not tied to a specific instance.
What is differential inheritance?
Differential inheritance is a concept in JavaScript where an object can directly inherit properties and methods from another object, serving as its prototype. Any changes to the prototype object are immediately reflected in the inheriting object.
What is the use of the blur function in JavaScript?
The blur() function in JavaScript is used to remove focus from the current focused element. It's often used in form validation scenarios to trigger validation checks when a user navigates away from an input field.
What is NaN?
NaN stands for "Not-a-Number" and is a special value in JavaScript representing an undefined or unrepresentable value resulting from a mathematical operation that doesn't yield a valid number.
What is the difference between ViewState and SessionState?
ViewState is used to store small amounts of data on the client-side between postbacks, while SessionState is used to store data on the server-side for a specific user session across multiple requests.
How to enable 'Strict' mode in JavaScript?
You can enable strict mode in JavaScript by adding the following line at the beginning of a script or a function: "use strict";. Strict mode helps catch common coding mistakes and makes JavaScript behave more predictably.
Is there automatic type conversion in JavaScript?
Yes, JavaScript supports automatic type conversion, also known as type coercion. It automatically converts data from one type to another when performing operations, which can sometimes lead to unexpected results.
What will happen if an infinite while loop is run in JavaScript?
If an infinite while loop is run in JavaScript, the browser or environment will become unresponsive, and the script will essentially freeze, causing high CPU usage and preventing other tasks from being executed.
What is the unshift method in JavaScript?
The unshift() method in JavaScript is used to add one or more elements to the beginning of an array. It modifies the original array and returns the new length of the array after adding the elements.
What are the decodeURI() and encodeURI() functions?
decodeURI() is used to decode a URI that has been encoded with encodeURI(). These functions help manage and manipulate URI components while preserving special characters.
Difference between window.onload and onDocumentReady?
window.onload waits for all assets (including images) to load before firing, while onDocumentReady (using libraries like jQuery) triggers when the DOM is ready, which may be before all assets are loaded.
What are JavaScript Cookies?
JavaScript cookies are small pieces of data stored on the user's browser. They can be used to store information such as user preferences or session data.
Can you access Cookies using JavaScript?
Yes, JavaScript can access cookies using the document.cookie property, which contains a string of all cookies associated with the current document.
- JavaScript Interview Questions (Part2)
- Is JavaScript a true OOP language?
- Advantages and Disadvantages of JavaScript
- Difference Between JavaScript and ECMAScript?
- What is noscript tag?
- Escaping Special Characters in JavaScript
- What is undefined x 1 in JavaScript?
- Logical operators in JavaScript
- Difference between '=', '==' and '===' operators in JS
- How to loop through objects in JavaScript?
- How to write html code dynamically using JavaScript?
- How to add html elements dynamically with JavaScript?
- How to load another html page from javascript?
- What Is The Disadvantages Using InnerHTML In JavaScript?
- What is Browser Object Model
- How to detect the OS on the client machine in JavaScript?
- Difference between window, document, and screen in Javascript?
- Difference between the substr() and substring() in JavaScript?
- How to replace all occurrences of a string in JavaScript?
- Test a string as a literal and as an object in JavaScript
- What is Associative Array in JavaScript
- What is an anonymous function in JavaScript?
- What is the use of 'bind' method in JavaScript?
- Pure functions Vs. Impure functions in javascript
- Is Javascript a Functional Programming Language?
- What's the Difference Between Class and Prototypal Inheritance?
- Javascript, Pass by Value or Pass by Reference?
- How to prevent modification of an object in Javascript?
- What is 'this' keyword in JavaScript?
- How Does Function Hoisting Work in JavaScript?
- What do mean by NULL in Javascript?
- What does the delete operator do in JavaScript?
- What is the Infinity property used for in Javascript?
- Event bubbling and Event Capturing in JavScript?
- What is "strict mode" and how is it used in JavaScript?
- What is the difference between call and apply in JavaScript
- Entire content of a JavaScript source file in a function block?
- What is an immediately-invoked function expression?
- What is escape & unescape String functions in JavaScript?
- Instanceof operator in JavaScript
- What Are RESTful (REpresentational State Transfer)Web Services?
- What is Unobtrusive JavaScript & Why it's Important?
- What Does JavaScript Void(0) Mean?
- What are JavaScript Cookies?
- Difference between Client side JavaScript and Server side JavaScript
- TypeError: document.getelementbyid(...) is null
- Uncaught TypeError: Cannot read property of undefined In JavaScript
- Null and Undefined in JavaScript