Core language vs. Web APIs
These two things confused me at the beginning, so I thought I’d get them out of the way.
An Italian comedian used to say “the answer you’re looking for is inside you… but it’s wrong”.
It’s not actually like that.
The core language only includes the following:
- language syntax (parsing rules, keywords, control flow, object literal initialization…)
- built-in objects and functions
- global object APIs
- prototype-based inheritance mechanism
- error handling mechanisms
- strict mode
Not just for browsers
Of course, it is found in virtually every browsers, but also servers (Node.js), NoSQL databases (CouchDB and others), software like OpenOffice, Photoshop, Adobe Acrobat, etc. etc.
Node adds objects and APIs to create servers and control HTTP, modules, etc. (I believe modules are the global object in Node).
CouchDB will expose an API to refine database results (via map/reduce functions, I believe). Other implementations will do their own thing.
[It] is classified as a prototype-based scripting language with dynamic typing and first-class functions. This mix of features makes it a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles.
The stuff above means:
- dynamic/a scripting language: it’s not compiled, but passed to the underling engine as plain text, and interpreted on the fly. This allows changing objects and other aspects of the program at runtime (dynamic typing)
- prototype-based: doesn’t use classes, but another mechanism for sharing information between objects called prototypal inheritance (or dynamic/differential inheritance)
- functions are first-class citizens, meaning that you can pass a function to another function, and a function can return another function
- it’s multi-paradigm, you can use different programming styles such as object-oriented, functional, or imperative
Objects are generic containers that work like kind of a mix between regular object and hash tables, and can be updated and augmented at runtime. This is extremely cool and powerful.
It doesn’t have classes, relying instead on a very expressive prototypal inhertitance implementation, which allows you to write flexible code and avoid refactoring and other cons of class-based languages. Instead of writing classes as instructions for how objects work, objects inherit directly from other objects.
It implements lambda. Functions are objects and therefore first-class citizens–meaning that they can be passed as parameters to other functions, and be used pretty much everywhere.
Hot JS/webdev content!
Delivered to your inbox