JavaScript is one of the most widely used and misunderstood programming languages in existence. Nearly every personal computer and mobile device in the world can interpret it, and nearly every developer (and non-developer) that has made a website has written it, some without knowing it!
If you call yourself a JavaScript developer, then here are some things that the language can do that you need to know about, whether you use them or not! If you are using them, then you should understand them!
Inheritance
Native JavaScript inheritance is prototypical. For one, this means that you don’t inherit from classes, you inherit from objects. You don’t define classes and instantiate them. Instead, you create objects and use them as a “prototype” or “base” for your own object instances. Read more about inheritance in JavaScript…
Private Variables
Because JavaScript uses prototype-based inheritance, there is no keyword to define a member as “private” or “protected”. Either the object has a member, or it doesn’t, and you can access that member from anywhere you can access the object. Do not despair! There is a way to implement private variables… using another feature of the language: closures! Read more about private variables in JavaScript…
Property Descriptors
Some of the most common complaints about JavaScript come from its dynamic, mutable nature. You can modify nearly any member of any object, add your own members, and even delete some built-in ones! This enables web developers to improve cross-browser compatibility of their sites while maintaining code readability with a technique called poly-filling. On the other hand, it also allows developers to modify built-in behavior (called “monkey-patching”), sometimes causing side-effects or bugs that are difficult to troubleshoot.
Starting in ECMAScript 5, new mechanisms have been defined to give you (the developer) the ability to restrict what can be done to your object members. Read more about property descriptors…
Strict Mode
Some good things happen when you enable strict mode. Probably the most notable is that some bad practices are exposed as syntax errors or exceptions. Other changes result in more protection pertaining to the use of “eval”. Some confusion is removed related to the “arguments” object. It even makes room to ease the implementation of future language features. Not to mention, the “use strict” declaration degrades gracefully to any previous version of the language! Read more about strict mode…
Follow-up
My goal is to help you become a better software developer, and a better JavaScript developer. In order to work towards that goal, my next few posts will dive in a little bit further to each of these areas.