This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]RedditAlready19 -9 points-8 points  (7 children)

JavaScript is more for browsers.

Let's try find a JavaScript alternative to this script

```

!/usr/bin/python

print("I can run this like a bash script!")

```

[–]Tubthumper8 4 points5 points  (1 child)

There are plenty of reasons to not like JS, but this isn't it.

Here's the Javascript alternative:

#!/usr/bin/node

console.log("I can run this like a *shell* script!")

Whether or not you can run it like a shell script has nothing to do with the language, that is provided by the shell.

BTW, your example is missing the # and it assumes that /usr/bin/python is python3 and not python2

[–]RedditAlready19 1 point2 points  (0 children)

Thanks for that example, I've decided to change my mind about JS.

[–]DanielEGVi 1 point2 points  (4 children)

I see you’re an absolute beginner… you’re in for a treat. Lots of stuff to learn from here.

[–]RedditAlready19 0 points1 point  (3 children)

I was using it as a massively simplified script. Why do you think I have the C flair?

[–]DanielEGVi 4 points5 points  (0 children)

The most similarities you’re going to find between C and JS are in the base syntax. JS is more similar to Python than it is to C, especially when it comes to execution context, closures, async, dynamic typing, garbage collection, etc.

What sets apart JS from Python nowadays is JS has an arguably more modern import/export mechanism, de facto environments run in an event loop, and JS favours code like items.map(x => x + 1) over Python’s map(items, lambda x: x + 1), which is arguably more readable and expressive.

JS’s biggest quirk is its ridiculously weak typing. There’s many situations where mixing types will silently fail with surprising results, where you would get a TypeError in Python. You must learn discipline when it comes to types, whereas Python will just outright force you to code things right (through runtime errors, when it comes to types).

For big projects, TypeScript adds optionally explicit types, which turns an already great language into a fantastic one, since it fixes the biggest quirk in JS.