When comparing JavaScript vs Bash (Bourne-Again SHell), the Slant community recommends JavaScript for most people. In the question“What is the best programming language to learn first?” JavaScript is ranked 14th while Bash (Bourne-Again SHell) is ranked 34th. The most important reason people chose JavaScript is:
If you run a web browser you already have JavaScript installed and can get started right away. Modern browsers such as Chrome also have very powerful programming consoles built into them. Aside from the browser console, you can also use online Javascript playgrounds such as JS Bin and JS Fiddle. Even from a tablet.
Specs
Ranked in these QuestionsQuestion Ranking
Pros
Pro No installation required
If you run a web browser you already have JavaScript installed and can get started right away. Modern browsers such as Chrome also have very powerful programming consoles built into them.
Aside from the browser console, you can also use online Javascript playgrounds such as JS Bin and JS Fiddle. Even from a tablet.
Pro Required for web development
If you are looking to create web projects, you will have to learn Javascript in order to develop the client side code. If you learn the foundations of programming in JavaScript you can reapply that education later in building web applications.
Pro Massive ecosystem
JavaScript has one of the largest programming ecosystems, as shown by the being the most popular language for projects on GitHub. As there are so many projects written in JavaScript there are lots of libraries available to build off of and many of them are written to be easy to use and integrate into other projects.
There are also lots of resources available for learning JavaScript. Other than traditional tutorials, language learning sites such as Codecademy have JavaScript courses. The Mozilla Developer Database also serves as a great resource for learning about the standard libraries built into JavaScript.
Pro Easy to build an application
By using the UI capabilities in HTML and CSS you can develop substantial applications with graphical interfaces more quickly and with less effort than in other languages which would require you to learn a windowing library.
Building a useful application is one of the best ways to learn a new language and because of the low learning curve for creating applications you can create more substatial programs and learn more practical programming priciple faster.
Pro Runs on both the browser and the server
With Node.js, it is now possible to run JavaScript as a web server. This would allow you to be able to create server based applications sooner than would if you had to learn a separate programming language as well for server side code.
As JavaScript is the only language supported by web browsers it puts it in the unique situation of being the only programming language that's available on both the client side and server side.
Pro First-class functions with lexical closures
While certainly not the only language with these features, this pro alone is so powerful that it compensates for most of JavaScript's problems. You'll learn to use closures and higher-order functions well in JavaScript, because you have to. And then you can generalize this knowledge to any other language that has these, and the good ones do.
Pro High demand for JavaScript developers
If you're looking for a career as a developer, JavaScript is the place to focus your attention. There is a huge demand for good developers especially in frameworks such as React and Angular.
Pro Complete dev stack can be run online
With codepen.io and other prototyping tools, you can learn Javascript from a mobile device. You don't even need a computer. It can be learned from an internet cafe or public library.
Pro JSON is native to JS
JSON is arguably a "must-learn". With JS, that's one less additional syntax to learn.
Pro Very good debugger
Has a built in debugger with break points, watches that work on local values, and a console that you can use to edit anything at any time. Both in the browser (eg: Chrome), and server (eg: Nodejs).
Pro Can be very simple (teachable)
By setting a few ground-rules (effectively coding in a subset of JS), JS is one of the simplest languages to learn (requiring very few must-learn prerequisite concepts).
Pro Great tools for development
Flow, JSHint/ESLint, Babel, npm, etc.
Pro Several Platforms to use the web stack and JS to create multi-platform apps
Opens the door to native application development as well as just websites. Use with React Native, Weex or Quasar (Vue), PhoneGap or Cordova, NativeScript... (etc) to build native apps. Use mostly the same code base for multi-platform and web.
Pro Atwood's Law "Any application that can be written in JavaScript, will eventually be written in JavaScript."
May also be a con.
Pro Modern ESNext is far better than the JS of days past
Modern JS has made great strides, and can be targerted to older (or non-standard) browsers using Babel. There are new language constructs that can make programming in JS comfortable.; e.g.: async / await ( <3 ).
Pro Instant gratification
While it's easy to argue that Python will give you 'instant gratification' (while actually ruining your understanding of good programming practices), JavaScript is far better in this regard. Make a small change to a page and it's immediately visible in the browser. You can throw in a JavaScript library like jQuery with minimal fuss.
Pro Speed (most implementations)
JS/ES is in the running for the fastest interpreted language given the optimizations and JIT integration of popular implementations. On the other hand, it fails utterly when compared with compiled (to native or VM code) languages.
Pro Integrates very well with UE4
Coding an immersive 3D game can retain the attention of new programmers. ncsoft/Unreal.js.
Pro Prototype based Object Oriented System
Being object oriented, it supports the predominate and powerful programming approach. Being prototype based, it provides an intuitive approach to OOP. Whereas other popular languages use classes, which focus on thinking in the abstract, Javascript's prototypes allow you to focus on thinking in the concrete.
For example, in a prototypical language, you think of a rectangle, and define it. You now have a rectangle. Let's say you want a red rectangle, you copy the rectangle and give it the property red. Want a blue one? Copy rectangle again give it a blue. Big blue rectangle? Copy blue rectangle and make it big. In a class-based language, first you describe a rectangle, describe a red rectangle as a type of rectangle, describe blue and big blue rectangles, and now that you have described them, you must create instances of them, and only then do you have the rectangles. Essentially: Classes are factories for objects, prototypes are objects themselves, and the latter method was created to be more intuitive, which is particularly advantageous to beginners.
Pro C-like syntax
After learning Javascript, you will feel at home in other languages as C-like syntax is very common.
Pro One of the most underestimated languages
deviously simple in syntax, yet highly powerful in paradigms, this language does not force you to the (actually intrinsically broken) object oriented paradigm, has a healthy dose of functional programming inside, and does not bloat the keyword space. Good javascript is all about structure. Bad javascript is all about lazy hipsters not taking the time to learn 'javascript, the good parts', a must read.
Pro Extremely popular
JavaScript usually tops the lists for most popular languages in use today and rightly so. It's used almost everywhere and it's in high demand, making it very easy to find a job for anyone who knows JavaScript. This helps make it desirable for a first language, as it will often be used in the future.
Pro The most used language in the whole Solar System in amount of scripts/applications
Because it runs in many different environments, it is the most used language in the world.
Pro Default shell on most systems
Bash is the default shell on virtually every UNIX system. Making it very portable across different systems and once you get used to it, you can use it everywhere.
Pro Plenty of examples and tutorials
Since this is very mature shell there is a lot of great examples and other resources describing how to do almost everything.
Pro Rich scripting capabilities on a single line
Want to run something 5 times? Write a throw-away loop: for i in 1 2 3 4 5; do date; done
If you need it 100 times? Not a problem: for i in {1..100}; do date; done
or: for ((i=0; i<100; ++i)); do date; done
How about emailing yourself when remote server is back online? Sure thing: while ! ping -c1 example.com &>/dev/null; do date; sleep 5; done && mailx -s 'server is back!' me@myself.com
Pro POSIX compatible
Pro Emacs-like keyboard control
By default, BASH uses shortcuts and concepts very similar to Emacs, so learning one often results in familiarity with the other.
Pro Rich built-in features
By default, there are many built-in features. They make really complex and reliable programs possible. In comparison to dash, for example, you can do the same tasks in less time and fewer lines of code.
Pro Variables and aliases are listed the way they are built
alias
and set
will list aliases and variables in a format that can be run directly with no modifications. Even if the values contain \n.
This is handy if you want to modify a value.
Pro Recursive globbing
ls **/*.log
for example is supported by Bash if you set shopt -s globstar
.
Pro Man page is a trove of wonders
While the manual "page" is nearly a hundred pages long, it is actually surprisingly succinct and stuffed with good information. It is often better than Googling for answers when writing shell scripts. The way it is written makes it easy to stumble upon useful new programming features just by flipping through it .
NOTE: If you find it dense and hard to read at the command line, look for the PDF version.
Pro vi mode is more comprehensive than on other shells
Vi editing mode works without a glitch. "_" will print you the last argument of the latest command (zsh won't). VI mode is fast off the bat - You don't have to reset any variable (like "KEYTIMEOUT" in zsh) for that.
Pro Copyright license is GPL 3+
Bash is licensed under the GNU General Public License ≥3, which gives much stronger assurances that the right to use it can't be restricted.
For example, Microsoft would not be able to claim in court that, even though they've distributed Bash with the GPLv3, a license that explicitly grants people freedom, now Bash is essentially proprietary due to software patents and everyone who uses Bash owes them money. (This may sound ludicrous to those who were not alive when Microsoft tried a similar scheme against Linux fifteen years ago).
The GPLv3 is a license that reflects the genuine ethical issues that arise when people give their time and skills to collaboratively build software. While most people wouldn't insist that their UNIX shell is licensed under the GPLv3+, it does matter and is a big PRO for Bash.
Pro Built-in 'help'... helps a lot
Built-in 'help' provides quick and efficient help on builtins and keywords.
Pro Rich scripting capabilities
BASH scripting is a rich and robust language.
Cons
Con Many errors pass silently
JavaScript looks for every possible way to treat the code you write as runnable and is very reluctant to point out likely errors. For example, you have call a function with too many arguments, the extra arguments are simply discarded.
Con Easy to accidentally use globals
If you forget a var
or new
, you can clobber the global scope. For tiny scripts (JavaScript's original use case) globals are great, but for larger applications globals are generally regarded as a Bad Thing. This is because changes to one small part of a program can randomly break things anywhere else. These kinds of bugs are notoriously hard to find.
Con Does not teach you about data types
Since JavaScript is a weakly typed language, you don't have to learn about data types if you start using JavaScript as your first language. Data types being one of the most important concepts in programming. This will also cause trouble in the long run when you will have to (inevitably) learn and work with a strongly or statically typed language because you will be forced to learn the type system from scratch.
Con Weird type coercions
'5' - 1 == 4
, but '5' + 1 == 51
. There are other examples that make even less sense.
Con Complex
JavaScript has a long litany of warts and gotchas. JavaScript will bite you if you're just a wee bit careless. You have to exercise a great deal of caution and awareness. You either have to know the entire 545-page ES6 spec to avoid them all, or use a linter to help restrict you from using the bad parts (and you still have to be familiar with the language), but beginners don't know these things. (Linters are also prone to time-wasting false positives.) This is a significant cognitive burden on even the experienced programmer (as if coding wasn’t hard enough already), but try learning to program in the first place on top of all of this and you'll understand that JavaScript is a terrible choice for the beginner.
Con Easy to fall into bad manners and bad mind structure
It wouldn't consolidate a good mind structure for moving to other languages. Too open.
Con Each browser has its own quirks when executing the same code in some cases
Beginner programmers often make the mistake of coding something, seeing it works in the browser they tested it in, and then scratching their heads when it doesn't work in another browser. Ideally you'd want a language that works consistently across all platforms in order to be able to focus more on the programming and less on the underlying environment. It just takes time away from learning and forces you to spend time figuring out why this worked in browser X but not browser Y.
Con The constant churn of tooling and language
Trying to keep up=javascript fatigue. You won't have time to learn anything else if this is your first language, and you will probably think all programmers are crazy. Plus web assembly may open the door for better alternatives.
Con Very confusing to read
Con The "this" keyword doesn't mean what you think it means
this
is bound to whatever object called the function. Unless you invoke it as a method. Unless you invoke it as a constructor. Unless it's an arrow function.
Con Limited standard library
Much often needed functionality is not in the standard library. (Contrast with Python.) However, there are well established libraries such as Lodash, to fill the gap (however, due to the diverse/fractured ecosystem it may not be clear what library to use).
Con Many tutorials, code, and resources, are structured for older ES5 code
Con Asynchronous coding is not easy for beginners
JavaScript can work synchronously but its current use is mainly around asynchronous instructions, and it's surely not a good way to start learning programming.
Con The `null` and `undefined` objects aren't really objects
Therefore, attempts to call methods on them will fail. This is especially frustrating since these are often returned instead of throwing exceptions. So a failure may appear far away from the actual cause, which makes bugs very hard to find.
Con Array-like objects
Many cases when you should get an Array, you just get an Array-like object instead and none of the Array methods work on it.
Con Fast moving
The language and the web platform move fast these days. this makes it difficult for students as there is a lot of fragmentation and outdated information.
Con Numbers that begin with 0 are assumed octal
This is very surprising for beginners. Especially since 00
through 07
seem to work just fine. And this isn't just for hardcoded numbers. The parseInt()
function has the same problem, but only on some systems.
Con Good tools are pretty much a MUST for new programmers
You really want to be using a good editor (light IDE) and a linter, type checker (e.g.:Flow), etc. until you grok the language. And choosing / setting-up that development environment is it's own learning curve. If taught in a classroom, using a subset of JS with solid tools, there is an argument that JS could be an ideal first language... however, that is a lot of ceremony to protect the new programmer from JS gotchas. But without the tools, JS can be a very painful painful first language (trying to figure out why your code isn't doing what you intended).
Con The language itself is not very appealing to developers.
JS is one of the most dreaded languages as it was designed for the purpose of becoming just an scripting language for a browser. It was never intended to take over as the leading technology in web development, thus the language has been streched past its own capabilities. A beginer should learn something else first, something that is better conceived and refined.
Con Counter-intuitive type conversion
JavaScript is rather inconsistent when dealing with different types. For example, when working with the + operator and two numbers, they will be added, two strings will be concatenated:
3+5; // 8;
"Hello "+"world"; // "Hello world"
When using +
with a string and a non-string operand, the non-string operand is converted to a string and the result is concatenated:
"the answer is "+42; // "the answer is 42"
"this is "+true; // "this is true"
In any other case (except for Date) the operands are converted to numbers and the results are added:
1+true; // = 1+1 = 2;
null+false; // = 0+0 = 0;
Con Fractured ecosystem
Angular, React, Ember, Meteor, Backbone, Knockout, Express, Mithril, Aurelia. The web frameworks pass in and out of fashion too quickly to keep up with. The endless civil wars are becoming tiresome.
Con Has really bad parts you're better off avoiding altogether
But beginners won't know better. And even after you learn, you might have to deal with others' code that uses the bad stuff. JavaScript was originally developed in 10 days. It just wasn't designed that carefully.
Con Extremely complicated and inconsistent rules
In Bash, exceptions are the rule, not even all being described by the main page.
There are a grand total of 5 different ways of quoting, sometimes even when one does not want to, for instance in command substitutions. These are all based around preserving the literal meaning of every character, with an exception list. There is even an exception list to the exception list in 4 of the 5, regarding how the backslash behaves! The behavior of the backslash is also one of the quoting rules, so naturally, it also has an exception in how it works when it stands before a newline as compared to other characters.
Bash has several layers of interpretations, all to be kept in mind:
The ~ expands to the home of the current user. So if you store it in a variable, can you use it that way? Nope: tilde expansion comes before variable expansion.
Aha, so that's how it works! Then, since applying quotation happens after redirections are set up, it must mean that redirecting within quotes works, right? Nope: there is an exception! If a redirection symbol is not quoted, quotation around the symbol is observed, but is not removed. So, since variable expansion also comes after setting up redirections, and no exceptions are described here in the man page, getting the name of a file from a variable and using it as a target should not work, right? No: redirection does not actually take place when the symbols are being read, the symbols are merely removed and are noted for later, right before when the actual command runs.
Apart from 5 types of quotation, there are basically 2 quoting phases, 2 word splitting phases (with only one being controllable), and a tokenization phase on top of that.
If you have a command, it could be an alias, a special built in, a non-special built in, a symbolic link to a file, a regular file, a function, with different rules regarding how they can be overridden, if redirection happens before or after arguments have been passed (what does "time my_command 2>&1 >log_file" do?), etc.
This list is admittedly long, but it doesn't even scratch the surface of the bloat, complexity and inconsistencies of Bash.
Con GPL3 is not compatible with Apple's lawyers
Apple, one of the largest distributors of UNIX systems, only ships an ancient version of bash that predates the iPhone.
No one knows why as Apple hasn't said, but the version Apple includes in MacOS is from right before the license was updated to version 3 of the GNU GPL (General Public License). Other major companies (IBM, Microsoft) have had no problem shipping the latest version of bash
, so it's unclear what Apple's lawyers are averse to. The GPL has always said that if you distributed a program, you granted everyone the right to use it freely. The biggest change in version 3 was the addition, "...and that includes software patents."
This was necessary because back in 2006 Microsoft was demanding that any company that uses Linux pay them or get sued for infringing on their patents. They even took some companies, like TomTom, to court. No software which can be restricted retroactively like that is truly free, so GPL 3+ includes a clause saying that if you distribute the program, then you are also granting license to any patents you own that are necessary to run it.
What patents Apple has that bash could possibly infringe on is a mystery, but the bigger question is, Why does Apple even care? So what if they are granting people the right to run bash without being sued by Apple. It's not like they were planning on doing that, right?
Even though it is not bash's fault that it is not Apple Lawyer-approved, this is a CON for it because a lot of people use Apple products. While there are methods like brew
to install a current version of bash, Apple does not make it obvious to their customers what they are missing.
Con Compatibility can be a curse
One of bash's claims to fame is compatibility with previous versions of itself and historic shells. But, doing that means that new features are often written in tortured, awkward syntax that is not easy to learn. For example, bash uses the POSIX way of doing arithmetic: to add 5+3 you must put the numbers in double parentheses with a dollar sign at the start: x=$((5+3)). It is true that many shells suffer from this same CON, but since bash is such an important shell, it has less wiggleroom to ditch clunky ideas that might break existing scripts.
Con Lags behind on features compared to ZSH and Fish
People who wants power features or to customize their shell experience use zsh or fish.
Con Filename expansion is not consistent
filename expansion is not consistent. "echo *" will print the names of the files in your current dir, if there are any... and will print "*" if there are none.
Con Non-intuitive shell expansion in for loops
If there are no .sh files, this will print mask itself:
for filename in *.sh; do
echo $filename
done
Con No out-of-the-box command autocompletion
To have command autocompletion in bash you need to install third-party plug-ins.
Con One of the most dangerous languages around
What it is mostly used for are file system operations. Guess what it is bad at? Operating on files. It automatically splits and carries out filename expansion on every single string resulting from variable expansion and command substitution unless quoted, by default on whitespace, whilst spaces are very common in filenames.
Before that, it even does pathname expansion, so woe to anywone who does not want to actually operate on files, but has a globbing metacharacter stored anywhere in a variable.
This means what you store in a variable is not going to be what will ACTUALLY be accessed.
If an empty variable is unquoted, it disappears completely due to word splitting, sometimes leading to applications signalling a missing parameter at a wrong position.
If quoted however, said variables cannot be iterated over in a loop, no matter what character one uses for word splitting.
If you use any globbing pattern with a command, be sure to use -- after the option arguments or if none are present, before starting the pattern with a mandatory ./
Otherwise, another Bash script run gone wrong or a hacker can create files named like an option ("-f", for instance) and your program will happily accept it as such, if it results from globbing.
For interactive use, it is convenient. For programming, it is a no-go.