JavaScript and client side scripting.
Moderator: General Moderators
-
WaldoMonster
- Forum Contributor
- Posts: 225
- Joined: Mon Apr 19, 2004 6:19 pm
-
Contact:
Post
by WaldoMonster »
I'm relative new to JavaScript and don't understand why the second script doesn't work.
Can someone explain that?
Code: Select all
<script type="text/javascript">
var list = ["Java", "Script"];
for (var i = 0; i < list.length; i++)
{
document.write(list[i]);
}
</script>
Code: Select all
<script type="text/javascript">
var list = array("Java", "Script");
for (var i = 0; i < list.length; i++)
{
document.write(list[i]);
}
</script>
-
jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Post
by jayshields »
It's because you cannot cast array's like that in JavaScript.
-
WaldoMonster
- Forum Contributor
- Posts: 225
- Joined: Mon Apr 19, 2004 6:19 pm
-
Contact:
Post
by WaldoMonster »
I found it,
The
Array class is case sensitive.
I assume this counts for all classes.
Code: Select all
<script type="text/javascript">
var list = new Array("Java", "Script");
for (var i = 0; i < list.length; i++)
{
document.write(list[i]);
}
</script>
-
superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign »
What programming language did you formerly use that wasn't case-sensitive?
-
WaldoMonster
- Forum Contributor
- Posts: 225
- Joined: Mon Apr 19, 2004 6:19 pm
-
Contact:
Post
by WaldoMonster »
superdezign wrote:What programming language did you formerly use that wasn't case-sensitive?
PHP functions are not case sensitive.
For example array a$ and b$ are both valid in PHP:
Code: Select all
<?php
$a = array('one', 'two');
$b = Array('one', 'two');
?>
-
feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Post
by feyd »
"array" isn't a function, but a language construct.
Function names aren't case sensitive in PHP, but variable names are. Most modern languages are case sensitive across the board.