javascript-interview-questions-answers

Basic Java Script Interview Questions and Answers

JavaScript is common and most powerful programming and scripting language being used today. JavaScript is a lightweight and client-side scripting language.
Although after may server-side supporting frameworks have been developed and JavaScript is used today as a powerful server-side tool. Most of the framework based on Javascript provides smooth user experience and seamless content rendering.
Due to huge populariy of JavaScript and frameworks there are huge oppourtunnities in JavAScript and Great potential of Hihgly paid Job. Google, Microsoft, Facebook, Amazon and almost all the big player in IT and software Industry are using JavaScript.
That why We need to focus on JavaScript Interview Questions to get a right job. We have designed the collection of Questions asked in JavaScript Inteview and are having Most Frequent Questions along with Answers.
Here you will find JavaScript Interview Questions and Answers usefull for any level of Expertise . Lets go for it:

What is Javascript?

Javascript is a client-side scripting language, used to enhance webpage functionality and User Experience.
JavaScript is a multi-paradigm, dynamic language with types and operators, standard built-in objects, and methods.
Its syntax is based on the Java and C languages — many structures from those languages apply to JavaScript as well.
What is the importance of Javascript in Web Development and Web design?
Javascript provide additional functionality to HTML elements. It handles the DOM and content dynamically. Javascript is used by all the giant players in software industries like Microsoft, Google, Facebook, Amazon, etc.
How can we define a variable in javascript?
We can define a variable in javascript using ‘var’ keyword. for example :

var userName = 'Vishal Agrawaal';

When JavaScript was created?
JavaScript was created in 1995 by Brendan Eich while he was an engineer at Netscape. JavaScript was first released with Netscape 2 early in 1996.

What was the earliest name of JavaScript?
It was originally going to be called LiveScript.

Is JavaScript Object-Oriented?
JavaScript supports object-oriented programming with object prototypes, instead of classes.

What are the methods to return output in javascript?
We use alert(),console.log() and document.write() to display output in javascript.

What are the main types of JavaScript?
JavaScript’s types are:

  • Number
  • String
  • Boolean
  • Function
  • Object
  • Symbol (new in ES2015)

What is an alert?
Alert is a dialog box to display some warning or error. It displays a message on dialogue and a close button or OK button by default.

How to get a value by the ID of the element?
We can find the value by using Javascript function
var employee_name = documenst.getElementById(‘element_id’).value;

What is DOM?
The HTML DOM model is a tree of Objects and Objects are created by HTML the elements when the page loaded. It allows us to access the content and allow us to manipulate the HTML elements’ properties and attributes dynamically using Javascript or other scripts.

What are the functions of JavaScript?
Functions are just Objects and can be used to do some particular task.

What is the event?
An event is an action that takes place followed by any DOM activity or manipulation. Javascript provides a vast range of events that helps to create interactive interfaces in HTML. For example : onchange, onclick, onblur, onfocus, onmouseover, onkeypress, onkeyup, onmouseout, onload, etc.

How to create a function in Javascript?
Syntax to create a function in javascript:

function myFunction(){
//function logic goes here
}

Can JavaScript replace PHP or JSP or ASP?
Never, Not comparable. Javascript is a client-side scripting language whereas PHP and others are the server-side scripting language. So there is no reason for replacement.

What are the standard Arithmetic Operations that are supported in JavaScript?
Arithmetic Operations Supported by JavaScrip:

    • Addition operator.
    • Subtraction operator.
    • Division operator.
    • Multiplication operator.
    • Remainder operator.
    • Exponentiation operator.

What are the equality operators in JavaScript?
The result of an equality operator is always of type Boolean :

  • (==) Equality operator.
  • (!=)Inequality operator.
  • (===)Identity operator.
  • (!==)Nonidentity operator.

Does JavaScript support shift operators?
Yes, Here are some operators to shift all bits of the operand.

  • << : Bitwise left shift operator.
  • >>: Bitwise right shift operator.
  • >>> : Bitwise unsigned right shift operator.

How can we create an array in JavaScript?
Here is the way to create array in JavaScript:

  • var my_array = [ ]
  • Var my_array = new Array()

Write a function using JavScript.

function printMyName(){

console.log(‘ My Name is Lakhan’);

}

How to define an array in Javascript?
Defining an array in javascript is similar to any other language:

var students=['Ram','Vishal','Rahul','Kallu','Ballu','Lallu'];

How to handle date in javascript?
Javascript provides a constructor Date(). We can use Objects created by Date() and can Handle dates. For example:

var date = new Date();
var today = date.getDay();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();

How to convert an array into a string in Javascript?
We have an array :

var cars = ["BMW", "Benz", "Toyota", "Ford"];
var carString= car.toString();

and the result will be BMW, Benz, Toyota, Ford.

What is the functionality of pop() in js?
pop() is a standard method in javascript and it removes the last element of an array when we apply.
for example, we can apply it to cars :

cars.pop();

Now cars array will be : [“BMW”, “Benz”, “Toyota”];

What is the functionality of push() in js?
pop() is a standard method in javascript and it adds an element at the end of an array when we apply.
for example, we can apply it to cars :

cars.push("FORD");

Now cars array will be : [“BMW”, “Benz”, “Toyota”, “Ford”];

What is the functionality of splice() in js?
splice() added element/s at the particular index of an array and can remove some elements from the index. It can be used to replace some elements in the array.

var cars = ["BMW", "Benz", "Toyota", "Ford"];
fruits.splice(1, 0, "Ferari");

Resulting array : [“BMW”, “Ferrari”,”Benz”, “Toyota”, “Ford”];
The first parameter is the index of the element where the new elements will be added and second is the number of elements will be removed from that index.

How to apply a for loop in an array in Javascript?
Example of for loop in javascript:

var text='';
for (var i = 0; i < cars.length; i++) { 
text += cars[i] + "
";
}
alert(text);

Spread the love
Dhananjay

Dhananjay

I’m Dhananjay — a free-spirit with a passion for technologies and blogging.

View all posts by Dhananjay →