JavaScript vs C
When comparing JavaScript vs C, the Slant community recommends C for most people. In the question“What is the best programming language to learn first?” C is ranked 3rd while JavaScript is ranked 14th. The most important reason people chose C is:
Learning C forces you to grapple with the low-level workings of your computer (memory management, pointers, etc.) in ways that the other languages abstract away. Without an understanding of these low-level aspects of computer programming you will be limited if you try to develop an application that needs to run in a memory or performance constrained environment. Other languages like Python can obscure a lot of details, so your foundation may be weaker.
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 Understanding of computers
Learning C forces you to grapple with the low-level workings of your computer (memory management, pointers, etc.) in ways that the other languages abstract away. Without an understanding of these low-level aspects of computer programming you will be limited if you try to develop an application that needs to run in a memory or performance constrained environment.
Other languages like Python can obscure a lot of details, so your foundation may be weaker.
Pro Helps with learning other languages later
A lot of languages used in the industry have a C-like syntax (C++, Java, Javascript, C#, PHP) and starting with C will help new developers to be familiar with it's syntax and by extensions with the syntax of many popular languages.
Pro Industry standard
C is the industry standard programming language, moreover, it is the most popular programming language to use. C is the language used for most Windows, UNIX and Mac operating systems.
Pro Portable
C is portable between most hardware. Generally a C compiler is made for any new architecture, and already exists for existing architectures.
C is portable between all operating systems (Windows, UNIX, Mac, etc.) and only needs a program to be recompiled to work. This allows anyone on any operating system to learn about the language and not be held back by intricacies of their operating system.
With this said, C's portability these days is not quite what it used to be. Much of said portability relies on the POSIX standard in particular, and as time passes, the compliance of a given system with that standard is becoming less certain; especially in the case of Linux. Most things will still be portable (or at least emulatable) between Windows, Linux, and FreeBSD for example; but you will at times need to make use of platform-specific support libraries and APIs as well.
Pro Must-have
Capability to program in C is greatly appreciated in developers, creates an image of competency, and many programmers will learn it at some point in their careers.
Pro Low level of abstraction
While higher level languages languages like Java and Python provide possibilities to be "more expressive" per line of code, it's much more convenient to start with "less efficient" (get me right) language, in order to get initial concepts of how things behave at lower level.
Actually C is a good starting point moving to both higher and lower levels of abstraction, the good example here would be learning C before Assembler, as for general use the Assembler quite hard to understand due to low level of its abstraction (like getting the understanding on how loops work in C before trying to implement them on Assembler).
Pro More control over the code
Pro The king of languages, imitated, extended but never equalled
Made of a small set of keywords and rules, only your imagination is the limit. Above all, when it comes to 'pro' programming, C is the only one to rely on.
Pro Teaches good practices
Writing in C will require you to understand how things are done. C implies using and understanding the fundamentals. Learning a higher-level language after is much easier.
Pro Portable between CPU architectures
C was designed to be independent of any particular machine architecture, and so with a little care, it is easy to write "portable" programs (see here). By design, C provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language like operating systems or small embedded systems.
Pro C is simple with lesser rules than any other language
C is standardized and it is the go-to language when you have to speed things up.
Pro Ubiquitous
There is a C compiler available for probably every computer system in existence today.
Pro Easy to drop down to assembly
Sometimes you really need to program directly in assembly. C’s ABI and common compiler extensions make this a piece of cake.
Pro If you can't grok C you should not be a professional programmer
It sets an early bar that if you can't hurdle you might as well do something other than programming and not waste any more of your time.
Pro Basic concepts can be applied to accelerate learning any other language
You can easily pivot knowledge learned here and apply it to almost every other language.
Pro Foundational, difficult but important
Learning C will teach valuable skills and transferrable understanding of computing. While learning a scripting language may be easier, students will not understand system constraints and performance problems, nor what features like garbage collection are actually doing in other languages.
Pro Low level langauge
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 Languages is full of corner cases and undefined behaviors
Undefined behavior in a program can cause unexpected results, making it hard to debug. With UB, program behavior may vary wildly depending on optimization settings. There are many cases that invoke UB, such as signed overflow, invalid dereferences, large integer shifts, uninitialized variables, etc. These serve to frustrate novice programmers when they could be learning other concepts.
Con Requires memory management
Learning programming is already hard enough when you don't have to worry about memory leaks.
Con Completely lacks type safety
The C standard library is not type safe, and the language itself does not promote type safety built into the language, which leads to error-proneness of the language. If anything, it would be recommended that those interested in C to instead put their time in D, which actually includes a complete copy of the C standard library rewritten to be fully type safe.
Con C will require you to learn concepts too advanced for most beginners
While other programmers will learn algorithms and structures and will do magic tricks and awesome applications, you will learn trash info that you should know maybe after 5-7 years experience in software development, not earlier. It's like going the first time as a seven year old kid to first school class, and your teacher tells you to learn you about Discrete Math, without basic math and how to do 2x2.
If you wish to be a really good programmer, C for sure will be in your portfolio, but not as a first language, and this programming language is used only for very hard and very limited tools which require a lot of professional skills from the programmer.
Con Does not support modules; header file annoyances
Header files are a poor man's implementation of modules. Modern programming languages make use of modules which eliminate the need for C includes and header files and the many issues caused by them, such as the complete lack of dependency checking. Header files often contain even more include statements that point to other header files which also point to even more which drastically increases compile time. Modules only have to be compiled once, and when importing those modules into your software project, you only have to pull in the module that you are using, which is often times already precompiled. This way, the compiler knows exactly what it needs before beginning to compile your project and can automatically compile the few dependencies it needs in advance rather than recursively compiling every header file it runs across as in C.
Con Steep learning curve
While the language compliments knowledge of computer components very well, and gives a deeper understanding, it is also quite difficult to learn, and to use correctly, especially without aforementioned knowledge.
Con Low-level
Depending on the purpose this can be either a pro or a con. If the task is to learn how to program, low-level of C will impend learning important concepts. Furthermore, C is rather limited in ways of building abstractions.
"Low-levelness" of C can be a pro feature in learning system programming.
Con Other languages can do it easier or better
There are languages like Rust, Object Pascal, D, Golang, Vlang, Odin, Zig, Jai, etc... that can be used instead. The other languages are easier to understand, use, and/or about as fast.
Con Compiles procedurally rather than intelligently
In the same manner that C recursively compiles header files ad infinitum without any sort of dependency checking, C source code is also compiled in the same manner. If you attempt to call a function before it is declared, the compiler will fail because the function was not compiled before it was caled.
Con Lack of support for first class strings
C does not support the string type, nor does it support UTF-8 strings that modern languages are employing today. Instead of strings, C makes use of the *char type which is a pointer to a character array.
Con Arrays are not first class objects
When an array is passed to a function, it is converted to a pointer, even though the prototype confusingly says it's an array. When this conversion happens, all array type information gets lost. C arrays also cannot not be resized, which means that even simple aggregates like a stack are complicated to implement. C arrays also cannot be bounds checked, because they don't know what the array bounds are.
Con Undefined behaviors and weak limited type safety
Subtle errors can render the entire program "undefined" by the complicated C standard. The standard imposes no requirements in such cases. Thus C compiler is free to ignore the existence of such cases and Bad Things are prone to happen instead. Even experts can't reliably avoid undefined cases in C, so how can beginners be expected to do so? C allows for non-type safe operations such as logic errors, wild pointers, buffer overflow, etc. UB and type safety issues create a large number of bugs and security vulnerabilities.
Con The need for C developers in the current market is very low, and trending downward
Older languages, like C, are no longer in their hay day. Even if you do learn it as your first language, you are only setting yourself up to need to learn another language in the long run. If you want a skill that you can not only learn from, but also potentially build a career on, C should not be your first choice.
Con Isn't truly portable or cross platform
The C programming language is not portable to other operating systems, and even different compilers, because the C language does not provide any reference cross platform libraries or compilers. Different platforms and compilers provide their own implementation of the C standard library which may not be compatible with the implementation in another compiler or platform. Without cross platform libraries and tools, one cannot state that C is portable. This is in stark contrast to modern programming languages that provide their own cross platform libraries and compilers, such as D, Go and Rust.
Con Only offers basic support for source code split into multiple files
Modern programming languages are capable of compiling split source code files by concatenating them together efficiently at compile time before compiling them. However, C requires the developer to resort to messing with header files and makefiles to get similar functionality.
Con C structs are very weak and outdated
C structs lack a lot of modern capabilities that are vital in programming languages of today, such as assigning member functions to structs to give them object-oriented capabilities, constructs, deconstructors and RAII. Great care must be used when using structs in C to prevent memory leaks and ridiculously slow structs.
Con Includes require obscene resources to compile
All the modern languages have resulted in ditching the ancient deprecated model of #include statements and have instead adopted the superior model of modules. When compiling software written in C, the programmer is forced to also compile X headers which contain Y headers which contain Z headers and so forth -- drastically increasing the number of lines that need to be compiled. In order to compile something as simple as "Hello, World", for example, 18K lines of code needs to be compiled. This can be very taxing on RAM and CPU resources, causing compile times to quickly absorb a large portion of the programming process.
Con Heavily outdated programming concepts
C lacks a large majority of programming concepts that modern languages make use of today. The existing functionality of C makes use of outdated and deprecated methodologies which can be of great annoyance to the modern day programmer.