Basic Java Script Interview Questions and Answers

By Dhananjay yadav March 15, 2018

What is Javascript?
Javascript is a client-side scripting language, used to enhance webpage functionality and User Experience.

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';


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

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 page loaded.It allow us to acces the content and allow us to manipulate the HTML elements properties and attributes dynamically using Javascript or other script.


What is 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 ect.


How to create a function in Javascript?
Syantx 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 other are the server-side scripting language. So there is no any reason for replacement.

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 anver an array into an string in Javascript?
We have an array :

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

and 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 on 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 on 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 form the index. It can be used to relace some element in the array.

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

Resulting array : ["BMW", "Ferari","Benz", "Toyota", "Ford"];
First parameter is the index of the elemnet where the new elemnet 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);








Post Tags:

No Comment to " Basic Java Script Interview Questions and Answers "