Sunday 31 July 2016

JavaScript Interview Questions

JavaScript Interview Questions

Here You can get Only important JavaScript Interview Questions

How do we add JavaScript onto a web page?

There are serveral way for adding javascript on a web page but there are two way with is commonly userd by developers
If your script code is very short and only for single page then following ways is best
a)You can place <script type="text/javascript"> tag inside the <head> element.

Code:

<head>
<title>Page Title</title>
<script language="JavaScript" type="text/javascript">
   var name = "Vikas Ahlawta"
   alert(name);
</script>
</head>

b).If your script code is very large then you can make a javascript file and add its path in the following way..

Code:

<head>
<title>Page Title</title>
<script type="text/javascript" src="myjavascript.js"></script>
</head>

How to access the value of a textbox using JavaScript?

Code:
<!DOCTYPE html>
<html>
<body>
Full name: <input type="text" id="txtFullName" name="FirstName" value="Vikas Ahlawat">
</body>
</html>

There are following way to access the value of the above textbox
var name = document.getElementById('txtFullName').value;
alert(name);

What are the way of make comment in Javascript?

// is used for line comments
ex:- var x=10; //comment text
/*
*/ is used for block comments
ex:-
var x= 10; /* this is
block comment example.*/

How you will get the CheckBox status whether it is checked or not?

var status = document.getElementById('checkbox1').checked;
alert(status);
it will return true or false

How to create arrays in JavaScript? 

There are Two way dor create array in Javascript like other languages..
a) first way to create array
Declare Array:-

Code:

var names = new Array();
Add Elements in Array:-
names[0] = "Vikas";
names[1] = "Ashish";
names[2] = "Nikhil";

b) this is second way
var names = new Array("Vikas", "Ashish", "Nikhil");



If an array with name as "names" contain three elements then how you will print the third element of this array?

Ans:- Print third array element document.write(names[2]);
Note:- array index start with 0

1 comment:

  1. Thanks for the useful JavaScript Interview Questions, as a beginner this helps to know about the frequent AQs which gave me much confidence during Interviews. Here are some useful AngularJS Training and Tutorials which I came across which also looks very Informative., Hope it helps for career development.

    ReplyDelete