If you like this site, I would appreciate a gift from my wishlist.

Don’t Abuse JavaScript!

Last Updated: 28-January-2010

Introduction

JavaScript has become popular due to being useful for scripting browsers, which is acceptable due to being the only commonly-acceptable portable choice for that. However, lately, it has been utilised as a host language for many other realms where there are far saner and superior alternatives.

This page aims to explain why JavaScript should not be abused for such stuff.

JavaScript Shortcomings

No sprintf

JavaScript has no sprintf-like function for formatting strings.

No date-formatting routines

In addition to that, JavaScript does not have a date formatting function.

Implicit scoping - var is optional

In JavaScript, variables can spring into existence with the var keyword being optional.

Line breaks terminate expressions

Line breaks (in addition to “;”) terminate expressions. This can cause many subtle errors.

Starting a closure is not convenient

One needs to type “(function () { function() { ... } })” to start a closure.

Foreach Loop

JavaScript’s foreach loop loops on the indices of the list instead of its values.

Swap Two Variables

JavaScript has no easy way to swap two variables.

Size of Associative Array

JavaScript's objects when used as associative arrays have no easy way to get the number of elements contained inside them.

Filter, map and forEach

Until recently, JavaScript had no built-in filter, map and forEach methods for arrays and they are only suppoorted in MSIE starting from version 9.

Lack of Numeric Ranges

JavaScript lacks numeric ranges.

The ‘this’ variable behaves erratically

The ‘this’ variable behaves erratically in JavaScript and cannot easily be relied upon.

No built-in way to repeat a string

JavaScript has no built-in way to repeat the concatenation of a string or an array several times.

Hall of Shame

Jokes