Stefan Ram wrote:
> Tim Streater <
timst...@greenbee.net> writes:
>> Javascript has nothing to do with Java except for having a similar
>> sounding name.
>
> There are so many similiarities between the two languages,
> that I can't name them all. For example, in both Java and
> JavaScript,
>
> 2 + "x"
>
> gives »"2x"«,
Does that really work in Java? Most certainly the following won't:
int x = 2;
String y = "x";
x + y;
> while in many other languages it does not.
> In both Java and JavaScript, the modulo operator »%« can be
> used for doubles,
Well, JavaScript has only "doubles" (actually, Numbers), but no integers
(I'm deliberately ignoring asm.js), so there's no point in defining an
modulo operator that wouldn't work with "doubles".
> while in many other languages, it cannot.
> Both have »instanceof« with a similar meaning, while other
> languages do not.
Counter-examples: C#, PHP.
> In both languages »x == x« is false, when
> x is NaN.
What is enforced by IEEE 754.
> And there are so many more similarities. And this
> is no surprise, as Brendan Eich, the creator of JavaScript,
> tells us:
>
> »The diktat from upper engineering management was that
> the language must "look like Java".«
>
> I have read this sentence »Javascript has nothing to do with
> Java except for having a similar sounding name« so often.
> One copies it from the other. But not one stops to think!
> Or to read. If one knows just a little bit about Java and
> JavaScript, it is obvious that they have so much in common.
Of course, JavaScript and Java have much in common. Mostly, that
JavaScript's syntax was designed to resembles Java's, even though early
versions of JavaScript and Java were *very* different. Early versions
of Java didn't even have closures (a basic building block of all but the
most trivial JavaScript scripts), and JavaScript doesn't have classes
until recently (and AFAIK these "classes" are still only a thin wrapper
over the more versatile prototypal inheritance).
Comparing JavaScript with Java is like comparing apples with oranges
(yes, both have a lot of similarities…). I consider somewhat recent
versions of PHP to be more similar to Java than JavaScript is, for instance.
--
Christoph M. Becker