Using Loop we can execute same block of code into a specific number of times.
JavaScript support two ypes of Loops:
1.for
2.while
1.for: We use for loop to execute a block of code for specfic number of times.
Syntax:
for (variable=startvalue;variable<=endvalue;variable=variable+increment)
{
code executed
}
Example:
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=5;i++)
{
document.write("Number is " + i);
document.write("<br />");
}
</script>
</body>
</html>
Output:
Number is 0
Number is 1
Number is 2
Number is 3
Number is 4
Number is 5
2.while: This loop execute block of code when specifc condition is true.
Syntax:
while (variable<=endvalue)
{
code executed
}
Example:
<html>
<body>
<script type="text/javascript">
var i=0;
while (i<=5)
{
document.write("Number is " + i);
document.write("<br />");
i=i+1;
}
</script>
</body>
</html>
Output:
Number is 0
Number is 1
Number is 2
Number is 3
Number is 4
Number is 5
3.do..while: In do..while Loop executed atleast one time after that it check the condition if it true than execution proceed otherwise loop stopped the execution.
Syntax:
do
{
code executed
}
while (variable<=endvalue);
Example:
<html>
<body>
<script type="text/javascript">
var i=0;
do
{
document.write("Number is " + i);
document.write("<br />");
i=i+1;
}
while (i<0);
</script>
</body>
</html>
Output:
Number is 0
JavaScript is an scripting language for the client side web development means web pages. It is designed by Brenden Eich comes in 1995.
Developer of JavaScripts are Netscape Communications Corporation, Mozilla Foundation. As name indicate you think it is essential related to Java. Its wrong its syntax matched with C Syntax,it use some java name and their convension. It is influenced by Seff,C,Scheme,Perl,Python,Java. Using this we can do many thimgs like: to improve Design,validate forms,detect browsers etc. JavaScript can be use by new programmer easily. I have given you some most important point related to JavaScript.
JavaScript is a trademark of Sun Microsystem.
It is dynamic,Weak and prototype language.
Using JavaScript we can make our HTML pages interactive.
JavaScript is a scripting language.
We can embedded JavaScript directly into HTML pages.
It is an interpreted language means for execution their is no need to pre-compilation of JavaScript. Latest version of JavaScript is 1.8/ 2008
Java (developed by Sun Microsystems) is a powerful and much more complex programming language in the same category as C and C++.
JavaScriptwas created by Brendan Eich at Netscape and was first introduced in December 1995 under the name of LiveScript. However, it was rather quickly renamed JavaScript, although JavaScripts official name is ECMAScript, which is developed and maintained by theECMA (European Computer Manufacturer\'s Association) International organization.
ECMA Organization developed and maintain ECMAScript.
An official JavaScript standard is ECMA-262.Development to of this started in 1996 and It is first used in ECMA General Assembly in june 1996.
It gets cettificated by international ISO (ISO/IEC 16262) standard in 1998.
It is usually based on JavaScript and Jscript Repectively given by Netscape and Microsoft.First it is invented by Brendan Eich at Netscape and applied on Navigator 2.0 after 1996 it is used on all type of Netscape and micrisoft browser.