SS-TECH LAB SEC-22 ,Noida, .

New Interview Question and Answer

Latest Interview Q/A
Currently Placed Student
Best Python Training Institute In Noida SS-TECH
Ajay Kumar
[ PHP Developer ]
QUICK QUERY

Latest JavaScript Interview Question and Answer
Q #1 ) What is JavaScript?

JavaScript is a scripting language. It is different from Java language. It is object-based, lightweight, cross-platform translated language. It is widely used for client-side validation. The JavaScript Translator (embedded in the browser) is responsible for translating the JavaScript code for the web browser.

Q #2 ) List some features of JavaScript.

Some of the features of JavaScript are:

 
 
 
 
 
 
 
 
Volume 0%
 
 
  • Lightweight
  • Interpreted programming language
  • Good for the applications which are network-centric
  • Complementary to Java
  • Complementary to HTML
  • Open source
  • Cross-platform

Q #3 ) List some of the disadvantages of JavaScript.

Some of the disadvantages of JavaScript are:

  • No support for multithreading
  • No support for multiprocessing
  • Reading and writing of files is not allowed
  • No support for networking applications.

Q #4 ) 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.write("Named Function");  
}  
msg(); 

Q #5 ) What is the difference between JavaScript and JScript?

Netscape provided the JavaScript language. Microsoft changed the name and called it JScript to avoid the trademark issue. In other words, you can say JScript is the same as JavaScript, but Microsoft provides it.

Q #6 ) How to write a hello world example of JavaScript?

A simple example of JavaScript hello world is given below. You need to place it inside the body tag of HTML.

<script type="text/javascript">  
document.write("JavaScript Hello World!");  
</script> 

Q #7 ) How to use external JavaScript file?

I am assuming that js file name is message.js, place the following script tag inside the head tag.

<script type="text/javascript" src="message.js"></script>

Q #8 ) Which symbol is used for comments in Javascript?

// for Single line comments and

/* Multi

Line

Comment

*/

Q #9 ) Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any?

Timers are used to execute a piece of code at a set time or also to repeat the code in a given interval of time. This is done by using the functions setTimeout, setInterval and clearInterval.

The setTimeout(function, delay) function is used to start a timer that calls a particular function after the mentioned delay. The setInterval(function, delay) function is used to repeatedly execute the given function in the mentioned delay and only halts when cancelled. The clearInterval(id) function instructs the timer to stop.

Timers are operated within a single thread, and thus events might queue up, waiting to be executed.

Q #10 ) Explain the difference between "==" and "==="?

"==" checks only for equality in value whereas "===" is a stricter equality test and returns false if either the value or the type of the two variables are different.

Q #11 ) What are all the types of Pop up boxes available in JavaScript?

  • Alert
  • Confirm and
  • Prompt

Q #12 ) What is the difference between an alert box and a confirmation box?

An alert box displays only one button which is the OK button.

But a Confirmation box displays two buttons namely OK and cancel.

Q #13 ) What are the different types of errors in JavaScript?

There are three types of errors:

  • Load time errors: Errors which come up when loading a web page like improper syntax errors are known as Load time errors and it generates the errors dynamically.
  • Run time errors: Errors that come due to misuse of the command inside the HTML language.
  • Logical Errors: These are the errors that occur due to the bad logic performed on a function which is having different operation.

Q #14 ) Enumerate the differences between Java and JavaScript?

Java is a complete programming language. In contrast, JavaScript is a coded program that can be introduced to HTML pages. These two languages are not at all inter-dependent and are designed for the different intent. Java is an object - oriented programming (OOPS) or structured programming language like C++ or C whereas JavaScript is a client-side scripting language.

Q #15 ) What is the use of isNaN function?

isNan function returns true if the argument is not a number otherwise it is false.

Q #16 ) What are JavaScript Data Types?

Following are the JavaScript Data types:

  • Number
  • String
  • Boolean
  • Object
  • Undefined

Q #17 ) How can you create an Array in JavaScript?

You can define arrays using the array literal as follows-

var x = [];
var y = [1, 2, 3, 4, 5];

Q #18 ) What are the variable naming conventions in JavaScript?

The following rules are to be followed while naming variables in JavaScript:

  1. You should not use any of the JavaScript reserved keyword as variable name. For example, break or boolean variable names are not valid.
  2. JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or the underscore character. For example, 123name is an invalid variable name but _123name or name123 is a valid one.
  3. JavaScript variable names are case sensitive. For example, Test and test are two different variables.

Q #19 ) 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.

Q #20 ) List out the different ways an HTML element can be accessed in a JavaScript code.

Here are the list of ways an HTML element can be accessed in a Javascript code:
(i) getElementById(‘idname’): Gets an element by its ID name
(ii) getElementsByClass(‘classname’): Gets all the elements that have the given classname.
(iii) getElementsByTagName(‘tagname’): Gets all the elements that have the given tag name.
(iv) querySelector(): This function takes css style selector and returns the first selected element.

Q #21 ) In how many ways a JavaScript code can be involved in an HTML file?

There are 3 different ways in which a JavaScript code can be involved in an HTML file:

  • Inline
  • Internal
  • External

An inline function is a JavaScript function, which is assigned to a variable created at runtime. You can differentiate between Inline Functions and Anonymous since an inline function is assigned to a variable and can be easily reused. When you need a JavaScript for a function, you can either have the script integrated in the page you are working on, or you can have it placed in a separate file that you call, when needed. This is the difference between an internal script and an external script.

Q #22 ) 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.

Q #23 ) What is a Typed language?

Typed Language is in which the values are associated with values and not with variables. It is of two types:

  • Dynamically: in this, the variable can hold multiple types; like in JS a variable can take number, chars.
  • Statically: in this, the variable can hold only one type, like in Java a variable declared of string can take only set of characters and nothing else.

Q #24 ) Name some of the JavaScript Frameworks

A JavaScript framework is an application framework written in JavaScript. It differs from a JavaScript library in its control flow. There are many JavaScript Frameworks available but some of the most commonly used frameworks are:

    Angular
    React
    Vue

Q #25 ) What is the difference between window & document in JavaScript?

 

Window Document
JavaScript window is a global object which holds variables, functions, history, location. The document also comes under the window and can be considered as the property of the window.

Q #26 ) What is the difference between innerHTML & innerText?

innerHTML – It will process an HTML tag if found in a string

innerText – It will not process an HTML tag if found in a string

Q #27 ) 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.