JavaScript

1. Java Script Module 2. World Wide Web (WWW) 3. Web Terms 4. NEED FOR SCRIPT 5. Introduction to Internet Programming 6. CLIENT SIDE and SERVER SIDE Scripting 7. Different Scripting Languages 8. Introduction to JavaScript 9. JavaScript and Security 10. How to Enable JavaScript 11. Advantages of Java Script 12. Limitations with JavaScript 13. Difference between JavaScript and JAVA 14. Difference between JavaScript and VBScript 15. JavaScript Development Tools 16. JavaScript Programming Techniques 17. JavaScript terms 18. Starting with JavaScript Programming step by step 19. Time to start JavaScript Programming 20. JavaScript Variables 21. JavaScript RESERVED WORDS 22. JavaScript Data Type 23. NUMBER DATA TYPE 24. BOOLEAN DATA TYPE 25. STRING DATA TYPE 26. NULL DATA TYPE 27. JavaScript Undefined DATA TYPE 28. JavaScript Operators 29. JavaScript Arithmetic Operators 30. JavaScript Logical Operators 31. JavaScript Comparison Operators 32. JavaScript String Operators 33. Bit Manipulation Operators 34. JavaScript Assignment Operators 35. JavaScript Conditional Operator 36. Conversion between JavaScript Data Types 37. Alert JavaScript function 38. confirm JavaScript function 39. prompt JavaScript function 40. JavaScript Statements 41. Single line & Multi-line Comments 42. JavaScrip If Statement 43. JavaScript if..else Statements 44. JavaScript If…else..if statement. 45. JavaScript For Statement 46. JavaScript For..in Statement: 47. JavaScript While Statement 48. JavaScript do while Statement: 49. JavaScript break and continue statement 50. JavaScript switch Statement: 51. JavaScript function() 52. JavaScript function with a Return Value 53. JavaScript with Statement 54. try, catch, and throw Statements 55. JavaScript ARRAY 56. JavaScript array of different data types 57. JavaScript ARRAY and Bubble sorting Program 58. JavaScript Array Methods 59. concate() method 60. every() method 61. filter() method 62. forEach() method 63. indexOf() method 64. Join() method 65. lastIndexOf() method 66. map() method 67. reduce() method 68. reduceRight() method 69. reverse() method 70. some() method 71. toSource() method 72. toString() method 73. pop() method 74. push() method 75. shift () method 76. slice () method 77. splice () method 78. sort() method 79. unshift() method 80. EVENT handling with JavaScript 81. onblur JavaScript Event 82. onchange JavaScript Event 83. onclick JavaScript Event 84. onDblClick JavaScript Event 85. onfocus JavaScript Event 86. onkeydown JavaScript Event 87. onkeyup JavaScript Event 88. Onkeypress JavaScript Event 89. onLoad JavaScript Event 90. onMousedown JavaScript Event 91. onMouseup JavaScript Event 92. Onmouseover JavaScript Event 93. onmouseout JavaScript Event 94. onMouseMove JavaScript Event 95. onReset JavaScript Event 96. onsubmit JavaScript Event 97. onUnload JavaScript Event 98. The Screen Object 99. JavaScript Interview Part1 100. JavaScript Interview Part2 101. JavaScript Interview Part3 102. JavaScript Interview Part4 103. JavaScript Interview Part5 104. JavaScript Interview Part6 105. JavaScript Interview Part7 106. JavaScript Interview Part8 107. JavaScript Interview Part9 108. JavaScript Interview Part10
Pr.Pg Next Pg

JavaScript Interview Questions and Answers Part 7

 

61. Is a javascript script faster than an ASP script?

  • 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..

 

62. Are Java and JavaScript the Same?

  • 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.

 

63. How to embed javascript in a web page?

  • javascript code can be embedded in a web page between

  • <script langugage="javascript"></script> tags

64. What is the difference between a web-garden and a web-farm?

  • Web-garden - An IIS6.0 feature where you can configure an application pool as a web-garden and also specify the number of worker processes for that pool. It can help improve performance in some cases.

  • Web-farm - a general term referring to a cluster of physically separate machines, each running a web-server for scalability and performance (contrast this with web-garden which refers to multiple processes on one single physical machine).

 

65. To put a "close window" link on a page ?

<a href='javascript:window.close()' class='mainnav'> Close </a>

 

66. To write messages to the screen without using "document.write()" ?

  • Changing the contents of an element is a much better solution. When the method showStatus is invoked it will change the content of the span.

...

function showStatus(message) {

var element = document.getElementById("mystatus");

element.textContent = message; //for Firefox

element.innerHTML = message; //for IE (why can't we all just get along?)

return true;

}

...

<span id="mystatus">Test. </span>

..

67. How to Add new elements dynamically ?

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<title>t1</title>

<script type="text/javascript">

function addNode() {

var newP = document.createElement("p");

var textNode = document.createTextNode(" I'm a new text node");

newP.appendChild(textNode);

document.getElementById("firstP").appendChild(newP);

}

</script>

</head>

 

<body onload="addNode();" style=" background: url('../images/Sand-1280.jpg'); background-color: yellow;">

 

<p id="firstP">firstP<p>

 

</body>

</html>

 

68. How to have an element invoke a javascript on selection, instead of going to a new URL: ?

<script type="text/javascript">

function pseudoClick() {

alert("Ouch!");

}

</script>

<a href="javascript:pseudoClick()">Click Here</a>

 

69. How to have the status line update when the mouse goes over a link ?

  • <a href="javascript.shtml"

  • onmouseover="window.status='Hi There!';return true"

  • onmouseout="window.status='';return true">Look at the Status bar</a>

  • Look at the Status bar as your cursor goes over the link.


70. How to setting a cookie with the contents of a textbox ?

  • Values stored in cookies may not have semicolons, commas, or spaces. You should use the handy "escape()" function to encode the values, and "unescape()" to retrieve them.

//Sets cookie of current value for myTextBox

function TextBoxOnchange() {

var myBox = window.document.getElementById(myTextBox");

document.cookie = "myTextBox="+ escape(myBox.value) + getExpirationString();

}

 

//return a string like ";expires=Thu, 5 Jan 2006 16:07:52 UTC"

function getExpirationString() {

var exp = new Date();

var threemonths = exp.getTime()+(120*24*60*60*1000);

exp.setTime(threemonths);

return ";expires="+exp.toGMTString();

}

 

This is called from the event handler in the HTML.

<input name="myTextBox" type="text" id="myTextBox"

onchange="javascript:TextBoxOnchange()" />

How to getting values from cookies to set widgets?

function getCookieData(labelName) {

//from Danny Goodman

var labelLen = labelName.length;

// read cookie property only once for speed

var cookieData = document.cookie;

var cLen = cookieData.length;

var i = 0;

var cEnd;

while (i < cLen) {

var j = i + labelLen;

if (cookieData.substring(i,j) == labelName) {

cEnd = cookieData.indexOf(";",j);

if (cEnd == -1) {

cEnd = cookieData.length;

}

return unescape(cookieData.substring(j+1, cEnd));

}

i++;

}

return "";

}

 

//init() is called from the body tag onload function.

function init() {

setValueFromCookie("brand");

setValueFromCookie("market");

setValueFromCookie("measure");

}

 

function setValueFromCookie(widget) {

if( getCookieData(widget) != "") {

document.getElementById(widget).value = getCookieData(widget);

}

}

 

//if you name your cookies the widget ID, you can use the following helper function

function setCookie(widget) {

document.cookie = widget + "=" +

escape(document.getElementById(widget).value) + getExpirationString();

}


Pr.Pg border                                              Next Pg