JavaScript Interview Questions


Q11: What is the concept event bubbling in JavaScript?

Ans: In the HTML DOM API, it is responsible for event propagation. When an event happens in an element, that too, inside another element. That occurs in such a way that these elements have entered a handle for that event. Due to event bubbling, at first, the event is captured and managed by the innermost element. After that, it propagates to outer elements. From that event, the execution process initiates and returns to its parent element. Later on, the execution shifts to its parent element. In short, it has three phases .i.e., Capturing phase: where the event moves to the element, the Target phase where the event gets to the target element, and the Bubbling phase where the event forms bubbles that moves up from the element.

Q12: What is NaN in JavaScript?

Ans: It is the abbreviation of Not a Number. Normally, it compares an unequal to any number. That also includes those that are not a number. Commonly, it identifies the condition of an error when a function doesn’t go back to a reasonable number. Hence, if you want to convert a string or any other element into a numeric value and you don't seem to figure out a way to do it. Then, you can use NaN to help you out.

Q13: How do JavaScript object and Primitive Data Types are passed in functions?

Ans: Firstly, there is a factor that makes Primitive Data Types and objects different. That is, primitive data types are passed by value. On the opposite side, reference passes objects through it.

The meaning of value is making a replica of the original. Imagine two siblings who are twins. They are born identical. However, if one of the twins loses his hand in a war, the other one won’t lose it too. Conversely, reference creates an alias to the original. For example, people have different pet names. That doesn’t mean that pet name is for your clone. It is for the same person. Nevertheless, two names can be used to call the same person.

Q14: What is a prompt box in JavaScript?

Ans: A prompt box provides a text box. Due to this, the user can enter the input. The prompt() technique gives a dialog box that makes the visitor input a value or anything. Most commonly, it is utilized when you require the visitor to input a value before they visit a page. When this box comes on the screen, the user will be given the choice to click either “OK” or “Cancel” to go ahead. This happens after adding an input value.

Q15: Define escape characters in JavaScript?

Ans: In JavaScript, escape characters help you to type special characters. This can be done without crashing your application. Escape characters (Backslash) can be used when you have to work with special characters, such as single quotes, double quotes, apostrophes, and ampersands. All you have to do is to put a backslash before adding the characters. Consequently, these characters will display once you do it. In JavaScript version 1.5, the escape() function was disapproved. That can be used for encoding a string. Because of this function, the string becomes movable. Thus, it can travel through any network to any system that allows ASCII characters.