Javascript Interview Questions and Answers in 2022
1. |
What is the full form of ECMA? |
European Computer Manufacturers Association |
|
2. |
What is DOM? |
The Document Object Model (DOM) is an application programming interface(API) for XML and HTML or fully object oriented representation of the web pages. It structure the web page as a group of nodes and objects that have properties and methods. The nodes can be removed, added, replaced, and modified easily by using the DOM API. |
|
3. |
What is BOM? |
The Browser Object Model (BOM) is consistent interface between javascript programs and web browsers. So it allows access and manipulation of the browser window. Like capacity to move, resize browser window or pop up a new browser window. | |
4. |
What is Javascript? |
Javascript is a lightweight programming language, it is used to make most interactive and dynamic web pages. It is most widely used because it can be easily integrated with HTML and almost all popular programming languages like PHP, Java, ASP .net. |
|
5. |
What is async attribute of script element? |
The async is a boolean attribute of the script element. This is set for an external script file. It downloads the script asynchronously without delaying the page load.
|
|
6. |
How to include external JavaScript file? |
We can include external JavaScript file by using the script tag
|
|
7. |
How to include JavaScript file from different server? |
We can include JavaScript file from different server by specifying full script path in src attribute.
|
|
8. |
How to check the datatype of a variable in JavaScript? |
The 'typeof' operator is used to check the datatype of a variable in JavaScript.
|
|
9. |
What is null datatype in JavaScript? |
Null data type is an empty object pointer and has only one value null. The below code alert object as output.
|
|
10. |
What is undefined datatype in JavaScript? |
When a variable is declared using var, but not defined, then by default it is initialized as undefined.
|
|
11. |
How to convert a Boolean value to number? |
The Number() function is used to convert object argument to number, when we pass Boolean true and false to the Number() function, then it will return 1 and 0 respectively.
|
|
12. |
What will happen when we pass a string as an argument in Number() function? |
If the string is empty, then the Number() function returns 0 otherwise it returns NaN. |
|
13. |
What is parseInt() function? |
The parseInt() first examines the first character of a number, if the first character is not a number or starting with a minus or a plus sign then it returns NaN. After examining the first character it goes to rest of the characters one by one. The parseInt() function also recognizes decimal, octal and hexadecimal integers.
|
|
14. |
What is parseFloat()? |
The parseFloat() recognizes the floating number and decimal number format.
|
|
15. |
How to convert a value to a string? |
By using the toString() method, we can convert a value to a string. This method returns string equivalent to a value.
|
|
16. |
Is it possible to overload function in JavaScript? |
No, In JavaScript, the function overloading is impossible. |
|
17. |
What is the difference between Primitive Data Type and Reference Data Type? |
Number, String, Boolean, undefined, null are Primitive Data Types. Primitive values are stored on stack, whereas Object, Array are Reference Data Types. The reference values are objects made up of multiple values and stored in the heap. |
|
18. |
Give some examples of script element attributes. |
These are attributes of script element. a) async, b) charset, c) defer, d) language, e) src, f) type |
|
19. |
What is the use of src attribute of the script element? |
The src attribute is used to include the external javascript file that is either located on the same server or different server.
|
|
20. |
Define Global Variable in JavaScript? |
A global variable has global scope. It is declared outside a function and can be accessed anywhere in the JavaScript code.
|
|
21. |
What is Anonymous Functions? |
The Anonymous function called using the variable name. To create a anonymous function, we do not need a function name. This functions are created at runtime.
|
|
22. |
What are the Event Handlers in Javascript? |
Event Handler invokes Javascript code when some event or action happends, such as on mouse click, mouse hover over some link. |
|
23. |
What is return statement in Javascript? |
The return statement is used inside a function to returns a value and exits from the current function.
|
|
24. |
Define const statement? |
The const statement declares a variable with a constant value. The const variable can be local or global. If it is declared within a function then its scope remain within that function block only. |
|
25. |
What is try.. catch block? |
The try...catch block provides to handle errors. The JavaScript code that may produce an error is written within try block. If an error occurs in the try block, then the program control is passed to catch block. If no error occurs, the program control is never pass to catch block. The catch block contain statements to handle the exception.
|
|
26. |
What is 'this' keyword in Javascript? |
The 'this' keyword is used to access the current object's properties. If we pass this on some event or function call, then we can access all the properties of that element within the function. | |
27. |
What is Math Object in javascript? |
Javascript has Math Object to perform mathematical operations on numbers. Math Object has several methods to handle different mathematical tasks.
|
|
28. |
How to get the Current Date in javascript? |
The getDate() method is used to get the current date. But for this, first we have to create object of Date() constructor.
|
|
29. |
What is Document Object? |
Everything on the web page is document object that is loaded in the browser window. Javascript call methods of the document object to work on the web page.
|
|
30. |
What is Window object? |
Window Object represents a browser window containing a DOM document. We can use it to set attributes for the browser window. For example, to set status bar message, we can use 'status' window property. |
|
31. |
Give some examples of window methods. |
These are the examples of window methods - alert(), open(), close(), prompt(), confirm() |
|
32. |
How you will insert JavaScript code in HTML page? |
We can insert JavaScript code in HTML page by the following way -
|
|
33. |
What is isNAN()? |
The isNAN() function returns true if the value pass in this function is not a number otherwise it returns false. |
|
34. |
How you will create object in JavaScript? |
We can create object in javascript by using new operator followed by the name of the object. Example - obj = new Object(); |
|
35. |
What is Logical NOT operator? |
Logical NOT operator represented by exclamation mark (!), it returns boolean value. First it converts the value to boolean value then negates it. Example -
|
|
36. |
Define do-while loop? |
Do while loop is almost similar to the while loop except that the loop statement is executed at least once. In this, the conditional check is written at the end of the loop iteration. So the statement is executed first before the condition is tested.
|
|
37. |
Define Break Statement? |
The break statement is placed inside the loop to terminate the iteration and start to execute the code immediately after the loop.
|
|
38. |
Define continue statement? |
The continue statement is used inside a loop. When continue statement is executed, it stops the current iteration of the loop and continue with the next iteration of the loop.
|
|
39. |
What is an array? |
An array is a collection of key/value pairs. We can store more than one item in a single variable. i.e. Array. So Array is used when there is requirement to add more items in a single variable. | |
40. |
Is JavaScript Garbage Collection language? |
Yes, JavaScript is a Garbage Collection Language, it automatically manage the memory allocation. It keeps track of variables that are in use or not in use and allocate the memory according to the requirement. | |
41. |
How will you reverse the array element in JavaScript? |
By using the reverse() method, we can reverse the elements order of an array.
|
|
42. |
Define forEach() method? |
This method is used to run function on every element of an array. | |
43. |
How will you get minimum and maximum values in a range in Javascript? |
By using Math min(), max() methods, we can find the minimum and maximum value in a range-
|
|
44. |
What is a prompt box? |
Prompt box is a method that pops up on browser's screen for user input. It contains some confirmation message or any kind of input from user. | |
45. |
How can you insert HTML code dynamically using JavaScript? |
We can insert HTML code dynamically using InnerHTML property.
|
|
46. |
How do you join two or more arrays? |
We can join two or more than two arrays by using the concat() method. This function returns a copy of the joined arrays. Syntax of concat() method -
|
|
47. |
What is the use of parse() method in Javascript? |
The parse() method takes a date string and returns the number of milliseconds since midnight of January 1, 1970.
|
|
48. |
What is the method to get random number in Javascript? |
The random() method is used to get random number between 0 and 1.
|
|
49. |
What is Regular Expression? |
Regular Expression is a sequence of characters that form a search pattern. This is used to perform pattern matching and search-and-replace functions on text. RegExp constructor is used to create a regular expression object. |
|
50. |
How can you print a webpage using JavaScript? |
We can print a webpage by using the window.print() function.
|
|
51. |
How JavaScript codes get executed? |
JavaScript is scripting language. JavaScript codes reside on the user's browser and interpreted and executed within the browser. |
◀ Previous
MySQL Interview Questions and Answers
MySQL Interview Questions and Answers
Next ▶
CSS Interview Questions And Answers
CSS Interview Questions And Answers
JavaScript Related Articles
Remove duplicates from array JavaScriptHow to reverse a number in JavaScript
How to reverse string in JavaScript
JavaScript display PDF in the browser using Ajax call
Parsing JSON in Javascript
Javascript speech recognition example
Select/deselect all checkboxes using Javascript
Print specific part of a web page in javascript
Dynamically Add/Delete HTML Table Rows Using Javascript
jQuery Ajax serialize form data example
Image popup on page load using HTML and jQuery
Ajax live data search using jQuery PHP MySQL
jQuery loop over JSON result after AJAX Success
Simple star rating system using PHP, jQuery and Ajax
jquery image zoom on mouseover example
Bootstrap star rating input example
Bootstrap datepicker example
Submit a form data without page refresh