Some JavaScript Interview Questions

Kesavi Kanesalingam
5 min readApr 5, 2020

--

1.What is JavaScript?
JavaScript is a client-side as well as server side scripting language that can be inserted into HTML pages and is understood by web browsers. JavaScript is also an Object based Programming language

2.What are the features of JavaScript?
- JavaScript is a object-based scripting language.
- Giving the user more control over the browser.
- It Handling dates and time.
- It Detecting the user’s browser and OS,
- It is light weighted.
- JavaScript is a scripting language and it is not java.
- JavaScript is interpreter based scripting language.
- JavaScript is case sensitive.
- JavaScript is object based language as it provides predefined objects.
- Every statement in javascript must be terminated with semicolon (;).
- Most of the javascript control statements syntax is same as syntax of control statements in C language.
- An important part of JavaScript is the ability to create new functions within scripts. Declare a function in JavaScript using function keyword.

3.What are the limitations of the JavaScript?
- Client-side JavaScript does not allow the reading or writing of files.
- It cannot be used for networking applications because there is no such support available.
- It doesn’t have any multithreading or multiprocessor capabilities.

4.What is the difference between “==” and “===” ?
” ==” only compares values “===” compare values and type both.

5.What is the difference between “undefine” and “NULL” Keywords?
undefined means a variable has been declared but has not yet been assigned a value.
null is an assignment value. It can be assigned to a variable as a representation of no value.

6.What is ‘this’ keyword in JavaScript?
The JavaScript this keyword refers to the object it belongs to. This has different values depending on where it is used. In a method, this refers to the owner object and in a function, this refers to the global object.

7.What is the difference between Attributes and Property?
Attributes- provide more details on an element like id, type, value etc.
Property- is the value assigned to the property like type=”text”, value=’Name’ etc.

8.What are the ways to define a variable in JavaScript?
The three possible ways of defining a variable in JavaScript are:
Var -The JavaScript variables statement is used to declare a variable and, optionally, we can initialize the value of that variable. Example: var a =10; Variable declarations are processed before the execution of the code.
Const -The idea of const functions is not allow them to modify the object on which they are called. When a function is declared as const, it can be called on any type of object.
Let - It is a signal that the variable may be reassigned, such as a counter in a loop, or a value swap in an algorithm. It also signals that the variable will be used only in the block it’s defined in.

9.What is the difference between undefined and undeclared?
undefined variables are those that are not assigned any value but declared in the program. if we try to read the value, an error message “undefined” is displayed. undeclared variables are those that are not declared in the program .If we try to read their values gives runtime error. But if undeclared variables are assigned some value then implicit declaration is done .

10.What is the difference between break and continue?
The main difference between break and continue is that break is used for immediate termination of loop. On the other hand, ‘continue’ terminate the current iteration and resumes the control to the next iteration of the loop.

11.What is NaN in JavaScript?
NaN is a short form of Not a Number. Since NaN always compares unequal to any number, including NaN, it is usually used to indicate an error condition for a function that should return a valid number. When a string or something else is being converted into a number and that cannot be done, then we get to see NaN.

12.What would be the result of 2+5+“3”?
Since 2 and 5 are integers, they will be added numerically. And since 3 is a string, its concatenation will be done. So the result would be 73. The “ ” makes all the difference here and represents 3 as a string and not a number.

13.What does the following statement declares?
var myArray = [[[]]];
It declares a three dimensional array.

14.How can you convert the string of any base to integer in JavaScript?
The parseInt() function is used to convert numbers between different bases. It takes the string to be converted as its first parameter, and the second parameter is the base of the given string. For example-parseInt(“4F”, 16)

15.Name some of the JavaScript Frameworks?
Angular
React
Vue

16.What are the different types of Error Name values in JavaScript?
There are 6 types of Error Name values. Each one of them is briefly explained as follows:
Eval Error -Thrown when coming across an error in eval() (Newer JS releases don’t have it)
Range Error -Generated when a number outside the specified range is used
Reference Error -It comes into play when an undeclared variable is used
Syntax Error -When the incorrect syntax is used, we get this error
Type Error - This error is thrown when a value outside the range of data types is tried to be used
URI Error -Generated due to the use of illegal characters

17.Define event bubbling?
JavaScript allows DOM elements to be nested inside each other. In such a case, if the handler of the child is clicked, the handler of parent will also work as if it were clicked too.

18.How can we stop event bubbling?
If you want to stop the event bubbling, this can be achieved by the use of the event.stopPropagation() method. If you want to stop the event flow from event target to top element in DOM, event.stopPropagation() method stops the event to travel to the bottom to top.

19.Define event capturing?
Event Capturing is the event starts from top element to target element. Modern browser doesn’t support event capturing by default but we can achieve that by code in JavaScript.

20.Why it is not advised to use innerHTML in JavaScript?
innerHTML content is refreshed every time and thus is slower. There is no scope for validation in innerHTML and, therefore, it is easier to insert rouge code in the document and, thus, make the web page unstable

--

--

No responses yet