Why I Love JavaScript: Uncovering Its Quirks and Powerful Features

Despite its reputation for oddities and browser inconsistencies, JavaScript has evolved with ES6 features like default parameters, arrow functions, template literals, destructuring, and more, making it expressive and efficient; this article explores those quirks and explains why the author prefers JavaScript for modern development.

21CTO
21CTO
21CTO
Why I Love JavaScript: Uncovering Its Quirks and Powerful Features

Introduction

Every developer has a favorite language. After reading this article you will understand why the author prefers JavaScript, even though some people dislike it.

Each programming language has its own oddities and challenges. JavaScript, in particular, exhibits many quirks, not because of the language itself but due to differing browser implementations of JavaScript engines. These inconsistencies pose challenges for web developers. Front‑end developers owe a debt of gratitude to libraries like jQuery, which abstract away much of the cross‑browser hassle, though the story does not end there.

Over the years JavaScript’s performance and syntax have improved dramatically. In this article I will first present JavaScript’s strange behaviors and then explain why I like the language.

JavaScript’s Quirky Behaviors

Developers often illustrate quirks with code because it is more direct than words.

// Comparison
x == x // returns true
x !== x // returns false

// Types
typeof NaN // returns "number"
"string" instanceof String // returns false

// Data
0.1 + 0.2 == 0.3 // returns false

// Parentheses matter
function f1() {
    return
    {
        name: 'my function'
    }
}
function f2() {
    return {
        name: 'my function'
    }
}
typeof f1() === typeof f2(); // false

There are many more syntactic oddities, but we will now turn to the newer, more pleasant features.

What I Like About Modern JavaScript

ES6 (ECMAScript 2015) introduced a powerful set of syntax improvements. Although I have been using JavaScript for a long time, each new feature makes me love the language more. Below are some of my favorite additions.

Default Parameters

Having used default parameters in Python, I find JavaScript’s version simplifies code by eliminating extra conditional logic.

function increment(i, inc = 1) { return i + inc; }

Arrow Functions

Arrow functions not only shorten filter and map expressions but also introduce handy methods such as some and every, reducing boilerplate.

[1, 2, 3].map(i => i + 1).reduce((s, i) => s + i)
[1, 2, 3].filter(i => i % 2 == 0).sort()
[1, 2, 3].some(i => i % 2 == 0)
[1, 2, 3].every(i => i % 2 == 0)

Template Literals

Template literals provide a cleaner way to build strings, eliminating many formatting headaches. They also allow embedded expressions, though they should be used judiciously.

let name = 'Gulnihal', postId = 3, commentId = 5;
console.log(`Hello ${name}`);
let url = `http://www.yusufaytas.com/posts/${postId}/comments/${commentId}`;
console.log(url);

Destructuring Assignment

Destructuring lets you extract values from objects and arrays concisely.

const [a, ...b] = [1, 2, 3]; // a = 1, b = [2, 3]
const {id, person} = { id: 3, person: {name: 'Gulnihal'} };
const newArray = [1, ...[2, 3]]; // [1, 2, 3]
const people = [{ id: 3, person: {name: 'Gulnihal'} }];
for (var {id: id, person: {name: name}} of people) {
    console.log(`The person with id=${id} is ${name}.`);
}

Beyond these, JavaScript also offers Promises, classes, and many other object‑oriented features that have transformed my daily development, allowing me to write less code that is more expressive.

In recent years JavaScript’s “smell” has improved noticeably. By accepting its quirky parts and avoiding the most odd syntax, we can enjoy a language that has become both powerful and pleasant.

Author: Yusuf Aytaş Translator: 21CTO Community Source: https://dzone.com/articles/why-i-like-javascript
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

frontendJavaScriptCode Exampleses6
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.