Labels

slider

Recent

Navigation

Top JavaScript technical Interview Question answers

Find here the Top JavaScript technical Interview Question answers for a better success in interviews conducted by software development companies
Top JavaScript technical Interview Question answers

Introduction

JavaScript was launched by Brendan Eich in the month of September, 1995 and within short period, it had become the most popular language for web application development purpose. 

After use of HTML, and CSS technologies, JavaScript becomes the third greatest web technology. 

1. What do you know about JavaScript?

Ans. JavaScript is a web scripting language which is different from Java web language. It is lightweight, object-oriented, and cross-platform translated web language. It is broadly utilized for client-side verification. The JavaScript Translator translates the JavaScript code for the well understanding of web browser.

JavaScript was designed to develop dynamic web pages. The JS program script may be added to the HTML code of any web page. When the web page gets loaded, these scripts get executed automatically and the web server must have JavaScript engine.

2. What are the different data types in JavaScript?

Ans. Following two types of data types are mainly used in JavaScript.

a.) Primitive types

i) String - It depicts single or multiple characters and is composed with quotes. A string can be represented using a single or a double quote.

Example:

ii) Number - It depicts a number and can be composed with decimals, or without decimals.

Example:

iii) BigInt - This data type is utilized to shelter the numbers which are above the restricted restriction applied on the Number data kind. It will be able to shelter large size integers and is represented by augmenting ‘n' to an integer.

Example:

iv) Boolean - It depicts a reasonable entity and can possess only two values : false or true. Booleans are commonly utilized for testing of conditional.

Example:

v) Undefined - Whenever a variable is contended but not assigned, it possesses the value of undefined and it's category is also unclear.

Example:

We can also assign the value of a variable as unclear.

vi) Null - It depicts a non-existent or an ineffective value.

Example:

vi) Symbol - It is a new type of data introduced in JavaScript ES6 that is utilized to shelter an unidentified and unique value.

Example:

2. Non-primitive types

Primitive data categories can possess only a single value. To possess multiple and complicated values, non-primitive data categories are utilized.

Object - It is utilized to possess group of data.

Example:

Note- It is crucial to keep in mind that any data category that is not a primitive data category, is of Object type in the platform JavaScript.

3. Write some important features of JavaScript. 

Ans. Some of the important features of JavaScript are:

  • Light weight
  • Good for the network-centric applications 
  • Interpreted programming language
  • Complementary to Java and HTML
  • Cross-platform
  • Open source

4. What was the first name of JavaScript?

Ans. During launch time, JavaScript was known as Mocha, and later it was known as Live Script and then has been popular as JavaScript till the date.

5. List some of the advantages and disadvantages of JavaScript.

Ans.

Advantages of JavaScript

  • Server interaction is less
  • Instant Feedback to the visitors
  • Highly Interactive
  • Rich Interface

Disadvantages of JavaScript.

  • No support for multithreading and multiprocessing
  • No assistance for networking applications.
  • No permission for writing and Reading of files

6. Define a named function in JavaScript.

Ans. The function which has been given a name at the time of giving definition is known as a named function.

For example

7. List the types of functions.

Ans. Various functions are given below:

a) Named - These kind of functions possesses name during giving of definition.

For Example:

b) Anonymous - These kind of functions never possess any name. They are announced dynamically at runtime.

8. Define anonymous function

Ans. It is a function that possesses no specific name. These functions are announced dynamically at runtime through the function operator rather announcement of function . Generally, the function operator is more adjustable than a function declaration. It can be effortlessly utilized in the place of an a manifestation. 

For example:

9. Can an anonymous function be allocated to a variable?

Ans. Yes, you can allocate an anonymous function to a specific variable.

10. What is an argument object in JavaScript ?

Ans. The JavaScript variables depict the arguments that are given to a function.

11. Define closure.

Ans. In JavaScript, we want closures while a variable which is distinguished outside the scope in reference is connected from some inner scope.

12. If we wish to return the character from a particular index which procedure is utilized?

Ans. The JavaScript string procedure charAt() is utilized to obtain char value available at the mentioned index. However, the index number begins from 0 and goes to n-1, where ever n is the size of the string. However, the index value can't become a negative, more or equal to the size of the string. 

For example:

13. Find out the difference between JavaScript and JScript?

Ans. Netscape delivered the JavaScript language and Microsoft named it as JScript to prevent the issue of trademark. JScript is similar to JavaScript, but Microsoft delivers it.

14. Find out the key differences between JavaScript and Java? / How is Java different from JavaScript?

Ans. JavaScript programming or scripting language is lightweight that is formulated by Netscape, Inc. It is utilized to enable web pages more interactive. Usually, It is not a portion of the Java platform. Following is a list of some main differences between  JavaScript and Java.

a) Definition

JavaScript is a lightweight and weakly written programming (scripting) language and has simpler syntax and rules.

Java is a comprehensive and strongly indexed programming language utilized for the purpose of backend coding. In Java, the variables need to be declared initially to get utilized in the program, and the   variable type is reviewed at the time of compile.

b) OOPs concept

JavaScript is popular as a client-side scripting language, and it never supports completely the OOPS concept. It occupies inside the HTML docs and is utilized to make web pages impressive, which is not obtainable with simple HTML.

Java is an OOPS (object-oriented programming) language or SPL (structured programming languages) such as C, C++, or .Net.

c) Running platform for code

The code designed by JavaScript is able to run only in the web browser, But, the things are changed now and the code of JavaScript will be able to run on the server through Node.js.

Java produces apps that could run in any Java Virtual Machine (JVM) or web browser.

d) Need of compilation

The code of JavaScript doesn't need to get complied.

The Java code requires to get compiled. 

e) Object Type

The Objects of JavaScript are prototype-based.

Since, Java Objects are class-based, you can't proceed to build any program in Java without making a class. 

f) Utilization area

JavaScript gets assigned within a specific web page and combines with the HTML content of it.

Java is known as a Standalone and Complete language that can be utilized in backend coding.

g) Memory consuption

JavaScript code can be utilized in HTML web pages and needs less memory.

Java programs absorb more memory.

h) File extension

The file extension of JavaScript is written as ".js" and it is generally interpreted but never gets compiled because of the client scripting language type. Every web browser has a JavaScript interpreter to get the JS code executed.

The file extension of the Java program is mentioned as ".Java" and it gets translated source code into the bytecodes that will be then executed by that specific JVM (Java Virtual Machine).

i) Multi threading

JavaScript never allows multithreading.

Java allows multithreading.

j) Concurrency

JavaScript utilizes an event-based strategy to concurrency.

Java utilizes a thread-based strategy to concurrency.

15. Name the falsy values in JavaScript, and how can we verify if a value is falsy?

Ans. Those values which are false while changing to Boolean are called falsy values.

For example

We can verify if a value is falsy by utilizing the the Double NOT operator (!!) or Boolean function.

16. What is hoisting in JavaScript?

Ans. Hoisting is the common method of JavaScript where all declarations of the variables and functions are shifted to top. Simply, we can explain that Hoisting is a procedure in which irrespective of where the functions and variables get declared, they are shifted on top place of the scope. The scope would be both global and local.

Example 1:

Example2:

Example3:  

17. How to write an example of JavaScript ‘Welcome World’ ?

Ans. A small example of JavaScript ‘Welcome World’ is illustrated below. You should mention it within the HTML body tag.

18. How to use external JavaScript file?

Ans. We are considering that js file name is myJS.js, mention the following script tag within the head tag.

19. Is JavaScript language case sensitive ?

Ans. Yes, JavaScript language is case sensitive .

For example:

20. What is BOM?

Ans. BOM stands for Browser Object Model. It contributes relations with the web browser. A window is the default object of a web browser. So, you can give name to all the window functions by mentioning the window name or directly. The object of window delivers different properties like document, screen, history, navigator, innerHeight, location, and innerWidth.

21. What is DOM? What is the actual usage of document object?

Ans. DOM refers to Document Object Model. However, a document object illustrates the HTML document. You can use it to get and alter the HTML content.

22. What is the usage of window object?

Ans. The window object gets developed automatically by the web browser that depicts a window of a web browser. It is not a right object of JavaScript, but web browser object.

The window object is utilized to exhibit the popup dialog box. Let's have a view on description - Method & its description as below:

Alert() 

Depicts the warning box having the message with button ok.

Confirm()

Depicts the confirm message box possessing the message with both button ‘ok’ and ‘cancel' .

Open()

Method helps in opening the new window.

Close()

Method helps in closing the current window.

Prompt()

Displays a dialog box to get input from the user.

SetTimeout()

Method executes the action after determined time like contacting function, assessing expressions.

23. What is the utilization of history object?

Ans. The history object of a web browser can be utilized to switch to history pages such as moving back and forward from the existing page or another page. 

Generally, there are 3 methods of history object.

  1. history.back() - It displays the previous page.
  2. history.forward() - It displays the next page.
  3. history.go(number) - The number would be positive for moving forward, and negative for moving backward. It displays the page as per the given page number.

24. How to write a comment in JavaScript?

Ans. Generally, there are two categories of comments used in JavaScript.

  • Single Line Comment: It is depicted by ‘//’ (double forward slash mark)
  • Multi-Line Comment: Slash with asterisk symbol is used for multi line comment. Example- /* mention comment here */

25. How to build a function in JavaScript?

Ans. To build a function in JavaScript, go through the following syntax.

26. How to compose HTML code dynamically utilizing JavaScript?

Ans. The innerHTML property is utilized to compose the HTML code through JavaScript dynamically. 

Example:

27. How to compose genuine text code by JavaScript dynamically?

Ans. The innerText property is utilized to compose the genuine text utilizing JavaScript dynamically.  

Example:

28. How to create objects in JavaScript?

Generally, you can create object in JavaScript in following 3 ways.

  1. By object literal
  2. By creating an illustration of Object
  3. By Object builder

Following simple code is given to create an object through ‘object literal' method.

29. How to create an array in JavaScript?

Ans. Generally, an array in JavaScript is created in 3 ways.

  1. By array literal
  2. By creating an illustration of Array
  3. By utilizing an Array builder

Following is a simple code to create an array through ‘array literal’ method.

30. What does the ‘isNaN()’ function?

Ans. The isNan() function returns true if the variable value is not a number. For example:

31. What is the output of 40+30+"70" in JavaScript?

Ans. 7070 because Sum of 40+30 will be 70. If the numeric value is given before and after +, it functions as binary addition arithmetic operator.

32. What is the output of "40"+30+70 in JavaScript?

Ans. 403070 because after a string all the + will be used for string concatenation purpos and not for arithmetic addition purpose.

33. How the ‘Client side JavaScript’ is different from ‘Server side JavaScript'?

Ans. The ‘Client-side JavaScript' comes with the basic JavaScript language and objects that are predefined and related to running JavaScript in a web browser. But, the client-side JavaScript is entrenched promptly through the HTML pages. The web browser interprets this JavaScript at runtime.

Server-side JavaScript also corresponds client-side JavaScript. It retains a relevant JavaScript which runs in a server. However, the server-side JavaScript are depicted just after compilation.

34. Where are cookies stored on the hard disk?

Ans. The cookies are stored on the hard disk depending on the type of Operating System (OS) and the web browser.

The Windows Netscape Navigator utilizes a ‘cookies.txt' file that possesses all the cookies and the path is ‘c:/Program Files/Netscape/Users/username/cookies.txt'.

The Internet Explorer stores the cookies on a file username@website.txt'. The path could be: ‘c:/Windows/Cookies/username@Website.txt'.

35. How ‘event.preventDefault()’ is different from ‘event.stopPropagation()’ methods in JavaScript?

Ans. When we work with JavaScript, the event.preventDefault() procedure is utilized to restrict the default aspect of an element.

For instance: 

If you utilize it in a structure element, it restricts it from fulfilling. If utilized in an anchor element, it restricts it from displaying. If utilized in a contextmenu, it restricts it from displaying.

However, the ‘event.stopPropagation()’ procedure is utilized to restrict the propagation of a specific event or restrict the event from appearing in the capturing or bubbling round.

36. How can you inspect if the ‘event.preventDefault()’ procedure was utilized in an element?

Ans. When we utilize the method ‘event.defaultPrevent()’ in the event object, it returns a Boolean demonstrating that the ‘event.preventDefault()’ method was called in a specific element.

37. How ‘undefined value' is different from ‘null value'?

Ans. Undefined value: An undefined value is not specified and does not possess keyword is called as undefined value. 

For example:

Null value: A null value is explicitly defined by the keyword "null" is called as a ‘null value'. 

For example:

38. How to put the cursor on waiting in JavaScript?

Ans. By utilizing the property "cursor", the cursor can be put on waiting in JavaScript. 

Example

39. What is this ‘[[[]]]’?

Ans. ‘[[[]]]’ is a 3-dimensional array.

40. What do you mean by negative infinity?

Ans. Negative Infinity is a specific number in JavaScript that can be obtained by dividing the -ve number by 0. 

Example:

41. How ‘view state' is different from ‘Session state'?

Ans. "View state" is distinct to a page in a particular session whereas "Session state" is distinct to a user or web browser that can be availed across all web pages throughout the web application.

Relevant Reading

  1. HTML: Difference Between Id And Name In Html
  2. Upload Image using jquery MVC
  3. Show Hide div on radio button using Jquery
  4. Capitalize the First Letter of String Using Jquery
  5. Email Validation using Jquery
  6. Jquery Timer Countdown in MVC Application
  7. Numeric Validation using Jquery

42. What are the pop-up boxes accessible in JavaScript?

Ans. The pop-up box such as Alert Box, Prompt Box and Confirm Box are accessible in JavaScript.

Example

Following code is the example of alert box (alert()) in JavaScript

Example

Following sample code is used for prompt() message box in JavaScript

Example

Following code is for confirm box ‘confirm()’ method in JavaScript

43. How can we identify Operating System of the client machine utilizing JavaScript?

Ans. The string ‘navigator.appVersion' can be utilized to identify the operating system on the client machine.

Top JavaScript technical Interview Question answers

44. How to submit a form utilizing JavaScript through clicking a link?

Ans. Following JavaScript code will be utilized for submission of the form through clicking the link.

45. Which is faster- ‘JavaScript' or ‘ASP script'?

Ans. JavaScript is faster because it doesn't need web server's assistance for execution of web page.

46. How to alter the background color of HTML document utilizing JavaScript codes?

Ans. You can use following code to alter the background color of the HTML document. 

47. How to control peculiarities in JavaScript?

Ans. We can control exceptions in JavaScript using ‘try/catch block'. JavaScript assists through keywords such as ‘try, catch, finally and throw' for exception treatment purpose.

48. How to validate a JavaScript form?

Ans. Using following code, we can validate a JavaScript form.

49. How to validate email in JavaScript?

Ans. Following set of code is used to validate email in JavaScript.

50. For which purpose, ‘this’ keyword is used in JavaScript?

Ans. ‘this' keyword is used as a reference variable which relates to the existing object. 

For example:

51. What is the need of debugging in JavaScript?

Ans. Initially, JavaScript didn't display any error message on a web browser. However, this mistake can influence the outcome. The best strategy to detect the error is to debug the JavaScript code. The code can get debugged smoothly by utilizing internet browsers like Google Chrome, Opera, Mozilla Firebox and Microsoft Internet browser.

To conduct debugging, we can utilize any of the following methods:

52. What is the utilization of debugger keyword in JavaScript?

Ans. The debugger keyword composed by JavaScript, establishes the breakpoint by the   code itself. The debugger restricts the performance of the program at the applied position. Now, we can proceed to begin the process of manual execution. If any exception happens, the execution will end again on that specific line.

For example:

53. What is the importance of a strict mode in JavaScript?

Ans. The strict mode of JavaScript, is utilized to create errors. It renders "use strict"; expression to make the strict mode active. Only, this expression can be positioned as the first declaration in a function or a script. 

For example:

54. What is the significance of Math object in JavaScript?

Ans. The math object of JavaScript, renders various constants and procedures to accomplish a mathematical operation. It has no constructors like date object.

For example:

56. What is the importance of a Number object in JavaScript?

Ans. The number object of JavaScript, allows you to illustrate a numeric value. It might be floating-point or integer. The number object of JavaScript fulfills the IEEE standard to illustrate the floating-point numbers.

57. What is the importance of a Boolean object in JavaScript?

Ans. The JavaScript Boolean is a crucial object that depicts value in two states such as: true or false. You can build the Boolean object of JavaScript, by Boolean() constructor.

58. What is the importance of a TypedArray object in JavaScript?

Ans. The TypedArray object of JavaScript, demonstrates a n array like a display of an underlying binary buffer of information. There is any nos. of many global properties, whose values may be TypedArray constructors for particular types of element.

59. What is the importance of a Set object in JavaScript?

Ans. The Set object of JavaScript is utilized to store the elements with distinct values. The contained values can be of any kind i.e. whether basic values or object sources.

For example:

60. What is the importance of a WeakSet object in JavaScript?

Ans. The WeakSet object of JavaScript is the category of group that permits us to store weakly possessed objects. The WeakSet are the groups of objects only like set. It doesn't possess the arbitrary values. 

For example:

61. What is the use of a Map object in JavaScript?

Ans. The Map object of JavaScript is utilized to map keys to specific values. It stores every component as key-value pair. It regulates the components such as find, edit and delete on the basis of particular key.

For example:

62. What is the importance of a WeakMap object in JavaScript?

Ans. The WeakMap object of JavaScript, is a kind of collection that is almost equal to Map. It stores each element as a key-value set format where keys are not strongly referred. Here, the keys are used as objects and the values are considered as arbitrary values. 

For example:

63. Find Difference between ‘==’ and ‘===’ operators.

Ans. Both ‘==’ and ‘===’ operators are type of comparison operators. The main difference between both operators is that ‘==’ is utilized to compare values whereas, ‘===’ is utilized to compare both values and kinds.

Example:

64. Find the difference between keywords ‘var’ and ‘let' in javascript.

Ans. Some differences between ‘var' and ‘let’ are as follows.

  1. The 'var' keyword was utilized in JavaScript earlier than the use of keyword 'let'. 
  2. The 'Var' keyword possesses a function scope. The variable is specified through ‘var' is available but in ‘let’ the facility of a variable stated with the 'let' keyword is restricted to the block in which it is announced. Let's begin with a Block Scope.
  3. In ECMAScript 2015, ‘const’ and ‘let’ were hoisted but not commenced. By giving reference to the block variable before the declaration of ‘let’ variable gives outcomes in a ReferenceError as the specific variable is in a "temporal dead zone" from the beginning of the block until the statement gets processed.

65. Explain Implicit Coercion in javascript.

Ans. Implicit coercion in javascript is the automatic transformation of value from one data type to another type. It happens when the operands of an a representation are of various data types.

a) String coercion

String coercion happens while utilizing the ‘+’ operator. When a number is included to a string, the number data type is often transformed to the string data type.

Example 1

Example 2

Note - ‘+’ operator when utilized to join two numbers, results a specific number. The same operator ‘+’ when utilized to join two strings, results the string in concatenated form:

In the following examples, we have included a number with a string,

When JavaScript finds that the operands of the specific expression x + y are of different categories (one type is a number and the other type is a string), it transforms the  number to the string and then conducts the procedure. Since after transformation, both the variable types are of string, the ‘+’ operator results the string that is concatenated ‘44’ in the first illustration and ‘25TC' in the 2nd illustration.

Note - The coercion Type also occurs while utilizing the ‘-’ operator, but the difference while utilizing ‘-’ operator is that, a specific string is transformed to a number and then subtraction occurs.

Illustration-1

b) Boolean Coercion

Boolean coercion occurs while utilizing logical operators, if statements, ternary operators, and loop checks. To realize the boolean coercion in if statements and logical operators, we have to know truthy and falsy parameters.

Truthy parameters are those which need to get coerced or transformed to true. Falsy parameters are those which need to get converted to false.

All parameters except false, 0, -0, 0n, and œ, undefined, null, and NaN are truthy parameters.

Example Of If statements:

C) Logical operators:

JavaScript Logical Operators do not return result true or false. They often return any one of the operands as per condition.

Function of some logical operators are described below.

AND ( && ) operator - If both the parameters are truthy, often the second parameter is returned. If the first parameter is falsy then the first parameter is returned or if the second parameter is falsy then the second parameter is returned.

OR ( | | ) operator - If the first parameter is truthy, then the first parameter is returned. Otherwise, often the second parameter gets returned.

Example:

66. Is javascript a statically or a dynamically written script? Give example.

Ans. JavaScript is known as a dynamically written language. In a dynamically written language, the variable type is verified at the moment of run-time in discrepancy to a statically written language, where a variable is verified during the time of compilation.

Since javascript is a dynamically or loosely written language, JS variables are not correlated with any category. A variable can possess the parameter of any category of data.

For example, the variable ‘a' is given a parameter type number can be transformed to a string :

67. What do you know about NaN property in JavaScript?

Ans- NaN property depicts the value ‘Not-a-Number’. It demonstrates a value which is not a proper number.

To review if a parameter is NaN, we utilize the function isNaN() ,

Note- isNaN() function transforms the given parameter to a category Number, and then associates to NaN.

68. Describe passed by value and passed by reference.

Ans. In JavaScript, the primitive data categories are considered as ‘passed by value' and non-primitive data categories are considered as ‘passed by reference'.

For realizing passed by value and passed by reference

69. Which syntaxes are used for making a RegExp object?

Ans. Following syntaxes are used to make a  RegExp object?

70. What do you mean by Augmenting classes?

Ans. Augmenting classes means the objects inherit prototype properties even in a dynamic state.

Share

Anjan kant

Outstanding journey in Microsoft Technologies (ASP.Net, C#, SQL Programming, WPF, Silverlight, WCF etc.), client side technologies AngularJS, KnockoutJS, Javascript, Ajax Calls, Json and Hybrid apps etc. I love to devote free time in writing, blogging, social networking and adventurous life

Post A Comment:

0 comments: