JavaScript Interview Questions


Q6: What is the major difference between null & undefined?

asjdbAns: The meaning of undefined for a variable is that when it has been declared, but no value has been assigned to it. As far as the null value is concerned, it is an assignment value. That means it is possible to assign it to a variable like a representation of no value. Speaking of representation, it shows the deliberate absence of any object value. It can be referred to as one of the most primitive values in JS. For boolean operations, you can treat it as falsy. Both of them are not at all identical. A null is an object while undefined is a type.

Q7: What makes undeclared & undefined different from each other?

Ans: Those variables that are not present in a program are called undeclared variables. As it is evident from the name, they are undeclared as well. A runtime error is experienced when the program attempts to read the value of an undeclared variable. A variable becomes undeclared if it doesn’t utilize the var keyword. These variables are created on the windows or global object. Undefined variables don’t have a value, but they are declared in the program. As a result, an undefined value returns when the program attempts to study the value of an undefined variable. This is why they are entirely different from each other.

Q8: Write about the errors encountered in JavaScript?

Ans: The JavaScript displays a message on the screen when it experiences an error. Some identified errors are described below.

Load-time errors: These errors appear at the time of the page loading. These errors arise when you incorrect syntax. These can be seen as the page loads.

Logic errors: unlike the previous one, this error rises when you use a syntactically correct code, yet it fails to fulfill the required task. For instance, an infinite loop.

Runtime errors: you see this error when the program is running. For instance, when there are illegal operations, there is a division of a number by zero. In simple words, it reaches a non-existent region of the memory.

Q9: What do you mean by Screen objects?

Ans: These are the objects that aid in reading the information present on the client’s screen. Screen object has some properties. The properties of the screen objects that need to be outlined are mentioned below. Also, the name of these properties pretty much define their task.

  • AvailHeight: This property tells you the height of the client's screen.
  • AvailWidth: It states the width of the screen.
  • ColorDepth: To give depth of colors in the images on the client's screen, this property is used.
  • Height: This includes the taskbar and tells you the total height of the client's screen.
  • Width: With the help of this property, you can find out the total width of the client's screen that includes the taskbar as well.

Q10: Describe Strict Mode in JavaScript? and what is the method to enable it.

Ans: For the addition of specific compulsions to JavaScript, strict mode is used. When the strict mode is enabled, JavaScript displays errors for a code. Interestingly, even though this error may be problematic or dangerous for the system, it is not shown without the struct mode. There are certain blunders that are made that hinder the JS engines to work properly. We can get rid of them through the strict mode.

We can say that the word strict in used in a literal sense. In the former versions of JavaScript, these factors were not addressed.

The object of "use strict" is to show that the code must be used in strict mode. Recently, almost all browsers are compatible with the strict mode.