<!DOCTYPE html>
<html>
<head>
<title>For-In Statement Example 1</title>
</head>
<body>
<script type="text/javascript">
for (var propName in window) {
document.write(propName);
document.write("<br />");
}
</script>
</body>
</html>
|
<!DOCTYPE html>
<html>
<head>
<title>Break Statement Example 2</title>
<script type="text/javascript">
var num = 0;
outermost:
for (var i=0; i < 10; i++) {
for (var j=0; j < 10; j++) {
if (i == 5 && j == 5) {
break outermost;
}
num++;
}
}
alert(num);
//55
</script>
</head>
<body>
</body>
</html>
|
<!DOCTYPE html>
<html>
<head>
<title>With Statement Example 1</title>
<script type="text/javascript">
with(location){
var qs = search.substring(1);
var hostName = hostname; //unavailable when viewing from a local file
var url = href;
}
alert(qs);
alert(hostName);
alert(url);
</script>
</head>
<body>
</body>
</html>
|
<script type="text/javascript">
function doAdd(num1, num2) {
if(arguments.length == 1) {
alert(num1 + 10);
} else if (arguments.length == 2) {
alert(arguments[0] + num2);
}
}
doAdd(10); //20
doAdd(30, 20); //50
</script>
|
<script type="text/javascript">
function doAdd(num1, num2) {
arguments[1] = 10;
alert(arguments[0] + num2);
}
doAdd(10, 20); //20
doAdd(30, 20); //40
</script>
|
<script type="text/javascript">
function addSomeNumber(num){
return num + 100;
}
function addSomeNumber(num) {
return num + 200;
}
var result = addSomeNumber(100); //300
alert(result);
</script>
|