in reply to Proving that Perl influenced JavaScript for WP

Yes, I have noticed that there are many similarities between Perl and JavaScript...the way they handle numbers for example. A variable scalar can hold a string or number, and what you do with it or how you treat it is going to determine whether it's going to be used as a number or a string. Both Perl and JavaScript has the ? : << >> / + - + -- ++ *= /= %= -= += <<= >>= operators. In JavaScript the % modulo operator works a bit differently, but both Perl and JavaScript stores numbers the same way. In JavaScript, you can use arguments[] just like in Perl you can use @_ but in Perl they did away with named arguments. Both JavaScript and Perl have regexes, although JavaScript is a bit limited. When it comes to Unicode characters, Perl requires a module to work with unicode strings, but in JavaScript the support is builtin from the start. In fact, your JavaScript functions and variable names can have unicode characters in them. In JavaScript, you can name your variables to start with a $ sign and write code that resembles Perl. Both Perl and Javascript have the eval function. Perl has "last" and "next," while JavaScript has "break" and "continue." They do the exact same thing. Both Perl and Javascript are quite lenient in the way they parse the source code (unless you use strict and warnings).

Perl has vec(), pack() and unpack() and printf() and sprintf() which are entirely missing from JavaScript. Perl is very efficient at manipulating strings but not so fast working with arrays. JavaScript is just the opposite. It's very fast with arrays but slow with strings. Perl has hashes, while JavaScript has properties. I know, it's not the same, but it's a little bit similar.

  • Comment on Re: Proving that Perl influenced JavaScript for WP

Replies are listed 'Best First'.
Re^2: Proving that Perl influenced JavaScript for WP
by LanX (Saint) on Apr 01, 2025 at 15:30 UTC
    JavaScript or rather JS1.0 is mostly a baby Perl with Java syntax. The prototype object system from Self being the main difference (objects are kind of blessed hashes which inherit from other objects not classes)

    The claimed functional influence from Scheme is already present in Perl5. ( sub returns a function reference, making functions a first class object which can be treated like variables)

    Block scoping was later introduced into JS with let . ( var is a mess )

    The operators you list derive from C, a common predecessor for Perl and Java.

    Actually "typecasting" in JS is a major problem, JS has no "scalars".

    To better explain, there are two major ways to do dynamic typing.

    A) a type is determined when initializing.

    Like in Python where 3/2 is 1.

    Why? Because 3 and 2 are integers. (Python introduced something like // later to address the confusion)

    B) a type is determined by the operator.

    Like in Perl where 3/2 is 1.5 and 3 . 2 is 32

    JavaScript is a mongrel of both systems,

    and the rules how + behaves confuse(d) the shit out of people.

    You can remember that 1 + "1" is "11", but what will happen if you don't have full control about the types in the variables of a + b ?

    JS programmers must resort to tricks like

    'a+b+0' or 'a+b+""'

    (IIRC, this depends on precedence and I have to look it up to be sure UPDATE guess what, I got it wrong, have to correct this later.

    What's sure is that a+=0 becomes a number and a+="" a string )

    Perl fixed this with a lot of operators, but people complain that the code looks unreadable, because of all the symbols.

    But Brendan had 10 days to design the language which had to look like Java...

    They fixed a lot of stuff in the meantime and introduced some nice python features.

    But it's still annoying not to have pure hashes in JS ...

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery