JavaScript Interview Questions

• Ans:JavaScript is a scripting language most often used for client-side web development.
• Both JavaScript and Jscript are almost similar. JavaScript was developed by Netscape. Microsoft reverse engineered Javascript and called it JScript.
• There are several way for adding JavaScript on a web page, but there are two ways which are commonly used by developers.
If your script code is very short and only for single page, then following ways are the best:</br> a).You can place <script type="text/javascript"> </script> tag inside the <head> element.
<head>
<title>Page Title </title>
<script language="JavaScript" type="text/javascript">
var name = "Tutortek"
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:
<head> <title>Page Title </title> <script type="text/javascript" src="myjavascript.js"> </script> </head>
• Yes!
• A function getElementById is not the same as getElementbyID
String, Number, Boolean, Function, Object, Null, Undefined.
• “==” checks equality only,.
•“===” checks for equality as well as the type.
• ex:-
<html> <body> Full name: <input type="text" id="txtFullName" name="FirstName" value="Manish verma">
</body>
</html>
• There are following ways to access the value of the above textbox:
var name = document.getElementById('txtFullName').value; alert(name);
• we can use the old way:
document.forms[0].mybutton. var name = document.forms[0].FirstName.value; alert(name);
• // is used for line comments ex:- var x=10; //comment text /* */ is used for block comments
• var status = document.getElementById('checkbox1').checked; alert(status);
will return true or false.
• There are two ways to create array in JavaScript like other languages:
a) The first way to create array Declare Array:
var names = new Array();
Add Elements in Array:-
names[0] = "manish";
names[1] = "kumar";
names[2] = "verma";
• Print third array element document.write(names[2]);
Note Array index starts with 0.
• Use document.forms[0].submit();
• It returns true if the argument is not a number.
Example:
document.write(isNaN("Hello")+ ")
; document.write(isNaN("2013/06/23")+ ")
; document.write(isNaN(123)+ ");
Output will be:
true
true
false
• The math object provides you properties and methods for mathematical constants and functions.
ex:-
var x = Math.PI; // Returns PI var y = Math.sqrt(16); // Returns the square root of 16 var z = Math.sin(90); Returns the sine of 90
• In JavaScript the this is a context-pointer and not an object pointer. It gives you the top-most context that is placed on the stack. The following gives two different results (in the browser, where by-default the windowobject is the 0-level context):
var obj = { outerWidth : 20 }; function say() { alert(this.outerWidth); } say();//will alert window.outerWidth say.apply(obj);//will alert obj.outerWidth
• Since 1 is a string, everything is a string, so the result is 124.
• Since 3 and 4 are integers, this is number arithmetic, since 7 is a string, it is concatenation, so 77 is the result.
• document.getElementById("myText").style.fontSize = "10";
-or- document.getElementById("myText").className = "anyclass";
• JavaScript 1.6(ECMAScript 5th Edition) support foreach loop,
• An object is just a container for a collection of named values:
var man = new Object();
man.name = 'Manish Verma';
man.living = true;
man.age = 23;
• var man = new Object();
name = ' Tutortek';
man.living = true;
man.age = 2;
man.getName = function() { return man.name;}
console.log(man.getName());
• Both will call String() constructor function You can confirm it by running the following statement:
console.log(myString.constructor, myStringLiteral.constructor);
• var myString = 'Tutortek' // Create a primitive string object.
var myStringCopy = myString; // Copy its value into a new variable.
var myString = null; // Manipulate the value
console.log(myString, myStringCopy);
Ans: // Logs 'null Tutortek'
.
• // Logs false, JavaScript does not care that they are identical and of the same object type. When comparing complex objects, they are equal only when they reference the same object (i.e., have the same address). Two variables containing identical objects are not equal to each other since they do not actually point at the same object.
• var object1 = { same: 'same' };
var object2 = object1;
console.log(object1 === object2);

What is this? var myArray = [[[]]];

Three dimensional array
• Number()
parseInt()
parseFloat()
Code here var n1 = Number("Hello world!"); //NaN var n2 = Number(""); //0 var n3 = Number("000010"); //10 var n4 = Number(true); //1 var n5 = Number(NaN);
Request a Call Back

Enter your Phone Number

Quick Contact

* Required Field

Reviews

Get A Free Quote / Need a Help ? Contact Us