JavaScript Interview Questions
 
Q: How to create a function using function constructor?
Ans : The following example illustrates this It creates a function called square with argument x and returns x multiplied by itself. var square = new Function ("x","return x*x");
Date submitted :3/22/2010 2:13:22 PM
Submitted by : shabir@myfaithsolution.com

Q: What does undefined value mean in javascript?
Ans : Undefined value means the variable used in the code doesnt exist or is not assigned any value or the property doesnt exist.
Date submitted :3/22/2010 2:14:02 PM
Submitted by : shabir@myfaithsolution.com

Q: How to access an external javascript file that is stored externally and not embedded?
Ans : This can be achieved by using the following tag between head tags or between body tags. script src="abc.js" /script where abc.js is the external javscript file to be accessed.
Date submitted :3/22/2010 2:14:31 PM
Submitted by : shabir@myfaithsolution.com

Q: What is JavaScript?
Ans : JavaScript is a platform-independent,event-driven, interpreted client-side scripting and programming language developed by Netscape Communications Corp. and Sun Microsystems.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: How to read and write a file using javascript?
Ans : I/O operations like reading or writing a file is not possible with client-side javascript. However , this can be done by coding a Java applet that reads files for the script.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: How to detect the operating system on the client machine?
Ans : In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Where are cookies actually stored on the hard disk?
Ans : This depends on the user's browser and OS. In the case of Netscape with Windows OS,all the cookies are stored in a single file called cookies.txt c:\Program Files\Netscape\Users\username\cookies.txt
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What can javascript programs do?
Ans : Generation of HTML pages on-the-fly without accessing the Web server. The user can be given control over the browser like User input validation Simple computations can be performed on the client's machine The user's browser, OS, screen size, etc. can be detected Date and Time Handling
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: How to set a HTML document's background color?
Ans : document.bgcolor property can be set to any appropriate color.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What does the "Access is Denied" IE error mean?
Ans : The "Access Denied" error in any browser is due to the following reason. A javascript in one window or frame is tries to access another window or frame whose document's domain is different from the document containing the script.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Is a javascript script faster than an ASP script?
Ans : Yes.Since javascript is a client-side script it does require the web server's help for its computation,so it is always faster than any server-side script like ASP,PHP,etc..
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Are Java and JavaScript the Same?
Ans : No.java and javascript are two different languages. Java is a powerful object - oriented programming language like C++,C whereas Javascript is a client-side scripting language with some limitations.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: How to embed javascript in a web page?
Ans : javascript code can be embedded in a web page between script langugage="javascript" script tags
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: How to access an external javascript file that is stored externally and not embedded?
Ans : This can be achieved by using the following tag between head tags or between body tags. script src="abc.js" /script where abc.js is the external javscript file to be accessed.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What is the difference between an alert box and a confirmation box?
Ans : An alert box displays only one button which is the OK button whereas the Confirm box displays two buttons namely OK and cancel.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What is a prompt box?
Ans : A prompt box allows the user to enter input by providing a text box.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Can javascript code be broken in different lines?
Ans : Breaking is possible within a string statement by using a backslash \ at the end but not within any other javascript statement. that is , document.write("Hello \world"); is possible but not document.write \ ("hello world");
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: How to hide javascript code from old browsers that dont run it?
Ans : Use the below specified style of comments script language=javascript or Use the some html codetags and code the display html statements between these and this will appear on the page if the browser does not support javascript
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: How to comment javascript code?
Ans : Use // for line comments and /* */ for block comments
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Name the numeric constants representing max,min values
Ans : Number.MAX_VALUE Number.MIN_VALUE
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What does javascript null mean?
Ans : The null value is a unique value representing no value or no object. It implies no object,or null string,no valid boolean value,no number and no array object.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What does undefined value mean in javascript?
Ans : Undefined value means the variable used in the code doesnt exist or is not assigned any value or the property doesnt exist.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What is the difference between undefined value and null value?
Ans : (i)Undefined value cannot be explicitly stated that is there is no keyword called undefined whereas null value has keyword called null (ii)typeof undefined variable or property returns undefined whereas typeof null value returns object
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What is variable typing in javascript?
Ans : It is perfectly legal to assign a number to a variable and then assign a string to the same variable as follows example i = 10; i = "string"; This is called variable typing
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Does javascript have the concept level scope?
Ans : No.Javascript does not have block level scope,all the variables declared inside a function possess the same level of scope unlike c,c++,java.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What are undefined and undeclared variables?
Ans : Undeclared variables are those that are not declared in the program (do not exist at all),trying to read their values gives runtime error.But if undeclared variables are assigned then implicit declaration is done . Undefined variables are those that are not assigned any value but are declared in the program.Trying to read such variables gives special value called undefined value.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What is === operator ?
Ans : ==== is strict equality operator ,it returns true only when the two operands are having the same value without any type conversion.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What does the delete operator do?
Ans : The delete operator is used to delete all the variables and objects used in the program ,but it does not delete variables declared with var keyword.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What does break and continue statements do?
Ans : Continue statement continues the current loop (if label not specified) in a new iteration whereas break statement exits the current loop.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: How to create a function using function constructor?
Ans : The following example illustrates this It creates a function called square with argument x and returns x multiplied by itself. var square = new Function ("x","return x*x");
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What’s relationship between JavaScript and ECMAScript?
Ans : ECMAScript is yet another name for JavaScript (other names include LiveScript). The current JavaScript that you see supported in browsers is ECMAScript revision 3.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What are JavaScript types?
Ans : Number, String, Boolean, Function, Object, Null, Undefined.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: How do you convert numbers between different bases in JavaScript? -
Ans : Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal 3F to decimal, use parseInt ("e;3F"e;, 16);
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What does isNaN function do?
Ans : Return true if the argument is not a number.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What is negative infinity?
Ans : It’s a number in JavaScript, derived by dividing negative number by zero.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What boolean operators does JavaScript support?
Ans : &&, || and !
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What does "e;1"e;+2+4 evaluate to?
Ans : Since 1 is a string, everything is a string, so the result is 124.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What’s a way to append a value to an array?
Ans : arr[arr.length] = value;
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com