Javascript Interview Questions for Your Job

Javascript Interview Questions for Your Job

JavaScript Interview Questions

1. What is JavaScript?

JavaScript is a scripting language. It is not quite the same as Java language. It is object-based, lightweight, cross-stage interpreted language. It is broadly utilized for customer side approval. The JavaScript Translator (installed in the program) is in charge of deciphering the JavaScript code for the internet browser.

2. List some features of JavaScript.

Some of the features of JavaScript are:
  1. Lightweight
  2. Interpreted programming language
  3. Good for the applications which are network-centric
  4. Complementary to Java
  5. Complementary to HTML
  6. Open source
  7. Cross-platform

3. List some of the advantages of JavaScript.

  1. Some of the advantages of JavaScript are:
  2. Server interaction is less
  3. Feedback to the visitors is immediate
  4. Interactivity is high
  5. Interfaces are richer

4. List some of the disadvantages of JavaScript.

  1. Some of the disadvantages of JavaScript are:
  2. No support for multithreading
  3. No support for multiprocessing
  4. Reading and writing of files is not allowed
  5. No support for networking applications.

5. Define a named function in JavaScript.

The function which has named at the time of definition is called a named function. For example
function msg()
{
document.writeln("Named Function");
}
msg();

6. Name the types of functions

The types of function are:
Named - These type of functions contains name at the time of definition. For Example:
function display()
{
document.writeln("Named Function");
}
display();
Anonymous - These type of functions doesn't contain any name. They are declared dynamically at runtime.
var display=function()
{
document.writeln("Anonymous Function");
}
display();

7. Define anonymous function

It is a capacity that has no name. These capacities are proclaimed progressively at runtime utilizing the capacity administrator rather than the capacity assertion. The capacity administrator is more adaptable than a capacity affirmation. It very well may be effectively utilized in the spot of an articulation. For instance:
var display=function()
{
alert("Anonymous Function is invoked");
}
display();

8. Can an anonymous function be assigned to a variable?

Yes, you can assign an anonymous function to a variable.

9. In JavaScript what is an argument object?

The variables of JavaScript represent the arguments that are passed to a function.

Define closure
In JavaScript, we need terminations when a variable which is characterized outside the degree in reference is gotten to from some inward extension.
var num = 10;
function sum()
{
document.writeln(num+num);
}
sum();

10. If we want to return the character from a specific index which method is used?

The JavaScript string charAt() strategy is utilized to discover a burn esteem present at the predefined file. The file number begins from 0 and goes to n-1, where n is the length of the string. The file esteem can't be a negative, more noteworthy than or equivalent to the length of the string. For instance:
var str="Bipin Web Academy";
document.writeln(str.charAt(15));

11. What is the difference between JavaScript and JScript?

Netscape gave the JavaScript language. Microsoft changed the name and called it JScript to dodge the trademark issue. As it were, you can say JScript is equivalent to JavaScript, however Microsoft gives it.

12. What is BOM?

BOM represents Browser Object Model. It gives association the program. The default object of a program is a window. In this way, you can call every one of the elements of the window by indicating the window or straightforwardly. The window object gives different properties like report, history, screen, guide, area, innerHeight, innerWidth,

13. What is DOM? What is the use of document object?

DOM represents Document Object Model. A record object speaks to the HTML archive. It very well may be utilized to access and change the substance of HTML.

14. What is the use of history object?

The history object of a program can be utilized to change to history pages, for example, back and forward from the present page or another page. There are three strategies for history object.
history.back() - It loads the previous page.
history.forward() - It loads the next page.
history.go(number) - The number may be positive for forward, negative for backward. It loads the given page number.

15. How to write a comment in JavaScript?

There are two types of comments in JavaScript.
Single Line Comment: It is represented by // (double forward slash)
Multi-Line Comment: Slash represents it with asterisk symbol as /* write comment here */
How to create a function in JavaScript?
To create a function in JavaScript, follow the following syntax.

function function_name(){
//function body
}

What is the difference between == and ===?
The == administrator checks balance just while === checks uniformity, and information type, i.e., an esteem must be of a similar sort.

16. How to create objects in JavaScript?

There are 3 different ways to make an article in JavaScript.
By article strict
  1. By making a case of Object
  2. By Object Constructor
  3. How about we see a basic code to make an article utilizing object exacting.

17. How to create an array in JavaScript?

There are 3 ways to create an array in JavaScript.
  1. By array literal
  2. By creating an instance of Array
  3. By using an Array constructor

18. What does the isNaN() function?

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

function number(num) {
if (isNaN(num)) {
return "Not a Number";
}
return "Number";
}
console.log(number('1000F'));
// expected output: "Not a Number"

console.log(number('1000'));
// expected output: "Number"

19. What is the output of 10+20+"30" in JavaScript?

3030 because 10+20 will be 30. If there is numeric value before and after +, it treats as binary + (arithmetic operator).

function display()
{
document.writeln(10+20+"30");
}
display();

20. What is the output of "10"+20+30 in JavaScript?

102030 because after a string all the + will be treated as string concatenation operator (not binary +).

function display()
{
document.writeln("10"+20+30);
}
display();

21. Difference between Client side JavaScript and Server side JavaScript?

Customer side JavaScript includes the fundamental language and predefined objects which are pertinent to running JavaScript in a program. The customer side JavaScript is implanted straightforwardly by in the HTML pages. The program deciphers this content at runtime.
Server-side JavaScript likewise takes after customer side JavaScript. It has an applicable JavaScript which is to keep running in a server. The server-side JavaScript are conveyed simply after assemblage.

22. In which location cookies are stored on the hard disk?

The capacity of treats on the hard plate relies upon the OS and the program.

The Netscape Navigator on Windows utilizes a cookies.txt record that contains every one of the treats. The way is c:\Program Files\Netscape\Users\username\cookies.txt

The Internet Explorer stores the treats on a record [email protected] The way is: c:\Windows\Cookies\[email protected]

23. What is the real name of JavaScript?

The first name was Mocha, a name picked by Marc Andreessen, author of Netscape. In September of 1995, the name was changed to LiveScript. In December 1995, subsequent to getting a trademark permit from Sun, the name JavaScript was received.

What is this [[[]]]?
This is a three-dimensional array.

var myArray = [[[]]];

24. Are Java and JavaScript same?

No, Java and JavaScript are the two distinct dialects. Java is a powerful, verified and object-situated programming language though JavaScript is a customer side scripting language with a few confinements.

25. What is negative infinity?

Negative Infinity is a number in JavaScript which can be derived by dividing the negative number by zero. For example:
var num=-5;
function display()
{
document.writeln(num/0);
}
display();
//expected output: -Infinity

26. What is the difference between View state and Session state?

"View state" is explicit to a page in a session while "Session state" is explicit to a client or program that can be gotten to over all pages in the web application.

27. What are the pop-up boxes available in JavaScript?

  1. Alert Box
  2. Confirm Box
  3. Prompt Box

28. How can we detect OS of the client machine using JavaScript?

The navigator.appVersion string can be used to detect the operating system on the client machine.

29. Is JavaScript faster than ASP script?

Yes, because it doesn't require web server's support for execution.

30. How to handle exceptions in JavaScript?

By the assistance of attempt/get square, we can deal with special cases in JavaScript. JavaScript bolsters attempt, get, at long last and toss catchphrases for special case dealing with.

31. What is the requirement of debugging in JavaScript?

JavaScript didn't demonstrate any blunder message in a program. Notwithstanding, these slip-ups can influence the yield. The best practice to discover the mistake is to troubleshoot the code. The code can be repaired effectively by utilizing internet browsers like Google Chrome, Mozilla Firebox.

To perform troubleshooting, we can utilize any of the accompanying methodologies:
  • Utilizing console.log() technique
  • Utilizing debugger watchword

32. What is the use of debugger keyword in JavaScript?

JavaScript debugger catchphrase sets the breakpoint through the code itself. The debugger stops the execution of the program at the position it is connected. Presently, we can begin the stream of execution physically. On the off chance that a special case happens, the execution will stop again on that specific line.. For instance:
function display()
{
x = 10;
y = 15;
z = x + y;
debugger;
document.write(z);
document.write(a);
}
display();

33. What is the role of a strict mode in JavaScript?

The JavaScript strict mode is utilized to creates quiet mistakes. It gives "utilize strict"; articulation to empower the strict mode. This articulation must be set as the main proclamation in a content or a capacity. For instance:
"use strict";
x=10;
console.log(x);

34. What is the use of Math object in JavaScript?

The JavaScript math object gives a few constants and strategies to play out a numerical activity. Dissimilar to date object, it doesn't have constructors. For instance:
function display()
{
document.writeln(Math.random());
}
display();

35. What is the use of a Boolean object in JavaScript?

The JavaScript Boolean is an object that represents value in two states: true or false. You can create the JavaScript Boolean object by Boolean() constructor.

function display()
{
document.writeln(10<20 br="" true=""> document.writeln(10<5 br="" false=""> }
display();

<20 br="" true=""><5 br="" false="">36. What is the use of a TypedArray object in JavaScript?

<20 br="" true=""><5 br="" false=""> The JavaScript TypedArray object represents an exhibit like a perspective of a fundamental double information support. There is any number of various worldwide properties, whose qualities are TypedArray constructors for explicit component types.
function display()
{
var arr1= [1,2,3,4,5,6,7,8,9,10];
arr1.copyWithin(2) ;
document.write(arr1);
}
display();