JavaScript Interview Questions

JavaScript Interview Questions




What is the difference between == and === ?
The == checks for value equality, but === checks for both type and value.

difference between innerHTML and append() in JavaScript?
InnerHTML is not standard, and its a String. The DOM is not, and although innerHTML is faster and less verbose, its better to use the DOM methods like appendChild(), firstChild.nodeValue, etc to alter innerHTML content.

break and continue statements?
Continue statement continues the current loop (if label not specified) in a new iteration whereas break statement exits the current loop. 



Javascript closures?
A closure takes place when a function creates an environment that binds local variables to it in such a way that they are kept alive after the function has returned. A closure is a special kind of object that combines two things: a function, and any local variables that were in-scope at the time that the closure was created.

What is Strict Mode in JavaScript?
Strict Mode has been introduced as part of ECMAScript 5 and introduces new, restricted variant of JavaScript which has following aims:
  • Throws errors for actions that are rather silly but previously didn’t throw an error
  • Throws errors for potentially unsafe actions
  • Disables functions that are poorly thought out
  • Potentially code in strict mode could run faster by eliminating mistakes that would make it difficult for JavaScript engines to perform optimizations
Is javascript case sensitive?
Yes javascript is case sensitive.
Examples are isNaN , Number, new Array().

How to set the cursor to wait ?
document.body.style.cursor = 'wait';
//do something interesting and time consuming
document.body.style.cursor = 'auto';  



What's Prototypes for JavaScript?  
Objects have "prototypes" from which they may inherit fields and functions. 

 a checkbox using Javascript?  
var checked = window.document.getElementById("thmyCheckBox").checked;
What does "5"+2+4 evaluate to?  
Since 5 is a string, everything is a string, so the result is 524.  
How to create arrays in JavaScript? 
 declare an array like this
var scripts = new Array();
We can add elements to this array like this

scripts[0] = "A";
scripts[1] = "B";
scripts[2] = "C";
scripts[3] = "D"; 
 


isNaN function?
Return true if the argument is not a number.  


GET and POST in HTML forms?
GETmethod: Parameters are passed in the querystring. Maximum amount of data that can be sent via the GET method is limited to about 2kb.
POST
method: Parameters are passed in the request body. There is no limit to the amount of data that can be transferred using POST. However, there are limits on the maximum amount of data that can be transferred in one name/value pair.
 


Differentiate between “var a=5” and “a =5” ?
difference is between the two is that one variable is local and the other is global.


How to get value from a textbox?

document.getElementById('txtbox1').value;

What are global variables?

Global variables are available throughout your code: That is, the variables have no scope. Local variables scope, on the other hand, is restricted to where it is declared (like within a function). The var keyword is used to declare a local variable or object, while omitting the var keyword creates a global variable.

// Declare a local variable
var localVariable = "testtest";
// Declare a global
globalVariable = "Cghdg";

What are JavaScript types?

• Number
• String
• Boolean
• Function
• Object
• Null
• Undefined

What is this keyword?

It refers to the current object.


how html Elements using javascript? 
the getElementById method is preferred.
document.getElementById("test").style.color = "green";

 


 

 


Related Posts:
  • javascript Date, Time Best seo practices How to promoting webpages Top seo tips top 10 e-commerce tips Additional seo tips Advanced seo tips Mobile seo tips Javascript Date The methods getDate(), getDay(), getMonth(), and g… Read More
  • HTTP “200 OK” response A complete request is not necessarily a successful request, andyour handler for the load event should check the status codeof the XMLHttpRequest object to ensure that you received anHTTP “200 OK” response rather than a “404 … Read More
  • JavaScript Interview Questions JavaScript Interview Questions What is the difference between == and === ? The == checks for value equality, but === checks for both type and value. difference between innerHTML and append() in JavaScript? InnerHTML is… Read More
  • var keyword JavaScript The var and function are declaration statements—they declare or define variables and functions. These statements defineidentifiers (variable and function names) that can be used elsewherein your program and assign values to … Read More
  • Prototypes Every Java-Script object has a second JavaScript object (or null, but thisis rare) associated with it. This second object is known as aprototype, and the first object inherits properties from theprototype.All objects created… Read More
  • Javascript cookie string We can set a cookie by setting document.cookie to a cookie string.  The following code will set a cookie with the UserName set as Paul,  and an expiration date of 28 December 2010. <html> <head> <… Read More
  • Creating a Cookie-Javascript To make life easier for ourselves, we'll write a function that allows us to create a new cookie and set certain of its attributes with more ease. We'll look at the code first and create an example using it shortly. fun… Read More
  • JavaScript Security Downloading and running programs written by unknown parties is a dangerous proposition. A program available on the Web could work as advertised, but then again it could also install spyware, a backdoor into your system, … Read More
  • Include Inline JavaScript code To include inline JavaScript code, place JavaScript code inside the <script> element directly, as follows: <script type=”text/javascript”> function sayHi(){ alert(“Hi!”); } </script> When using inline Java… Read More
  • WebSocket() constructor socket with the WebSocket() constructor:var s = new WebSocket("ws://ws.example.com/resource");The argument to the WebSocket() constructor is a URL that usesthe ws:// protocol (or wss:// for a secure connection like thatused … Read More
  • Javascript Array Creating an Object We have already seen an example of an Array object being created. To create an Array object, we used the JavaScript statement var myArray = new Array(); So how is this statement made up? The first ha… Read More
  • Reserved Words in JavaScript Reserved Words in JavaScript 1.5 >abstract else instanceof switch >boolean enum int synchronized >break export interface this byte extends long throw case f… Read More
  • concat() Method The concat() method returns the array resulting from appending its arguments to  the array on which it was invoked. Given the script: var myArray = ["red", "green", "blue"]; alert(myArray.concat("cyan", "yello… Read More
  • JavaScript Timers setTimeout() and setInterval() allow you to register a functionto be invoked once or repeatedly after a specified amountof time has elapsed. These are important global functions ofclient-side JavaScript, and are therefore de… Read More
  • Retrieving the Response A complete HTTP response consists of a status code, a set ofresponse headers, and a response body. These are availablethrough properties and methods of the XMLHttpRequestobject:• The status and statusText properties return t… Read More