"JavaScript 2023 Unwrapped: A Year in Review"

"JavaScript 2023 Unwrapped: A Year in Review"

The year 2023 has marked amazing Milestones in the world of tech. JavaScript (on the other hand) has been made better

Just in case you haven't already, you can check your GitHub Unwrapped stats by clicking on the link down below

https://githubunwrapped.com/

Let's look at the 4 major changes that have been made to JavaScript🚀🚀🚀

1.Hashbang Comments

Hashbangs are already being used in JavaScript, especially in Node.js scripts, but their handling was dependent on the host environment. Here’s an example of a Node.js script using a hashbang:

#!/usr/bin/env node
console.log("Hello, world!");

The difference lies in the underlying handling of these hashbangs, making JavaScript more consistent with other scripting languages and potentially easier to integrate with different ecosystems. Note that this feature is more relevant for server-side JavaScript and doesn’t change much for client-side JavaScript in browsers.

2.Change Array by Copy

This proposal introduces new methods for sorting, reversing, and overwriting data without mutating the array it’s stored in. This allows for more functional programming patterns and consistency in handling arrays and tuples.


Before: Mutating the Array*

let array = [3, 2, 1];
array.sort();

console.log(array); // Output: [1, 2, 3]

In the above example, we sorted the array, but the original array was mutated as a result of the sort() operation.

After: Using Change Array by Copy

let array = [3, 2, 1];
let sortedArray = array.sortCopy(); // Proposed method

console.log(array); // Output: [3, 2, 1]
console.log(sortedArray); // Output: [1, 2, 3]

In this example, we’re using the proposed sortCopy() method (the exact method name might differ in the final specification) to sort the array. This new method returns a new sorted array and leaves the original array unmodified.

This feature is part of the functional programming paradigm where data immutability is highly encouraged. By avoiding direct mutations in the original data, we can write safer and more predictable code. It should be noted that this example assumes the existence of a sortCopy() method as described in the proposal, but the future implementation could be different when this feature is officially released.

3.Array Find from Last

As the name suggests, this feature returns matching elements in an array starting at the end and working back, potentially improving performance or saving the need to write extra code.

Before: Using Array.prototype.find() and Array.prototype.reverse()

let array = [1, 2, 3, 2, 1];
array.reverse();
let foundValue = array.find((element) => element === 2);

console.log(foundValue); // Output: 2

In the above example, we reversed the array and then used find() to search for the first occurrence of the number 2 from the end of the array.

After: Using Array.prototype.findLast()

let array = [1, 2, 3, 2, 1];
let foundValue = array.findLast((element) => element === 2);

console.log(foundValue); // Output: 2

In this example, we’re using the proposed findLast() method (the exact method name might differ in the final specification) to find the first occurrence of the number 2 from the end of the array. This new method allows us to avoid reversing the array and makes our intention clearer.

Already available in recent versions of the main browsers (06/06/2023).

4.FindLastIndex

const array = [1, 2, 3, 2, 1];

const lastIndex = array.findLastIndex((x) => x === 2);

console.log(lastIndex); // Output: 3

In this example, findLastIndex is used to find the last occurrence of the number 2 in the array. The function passed to findLastIndex returns true for the number 2 and false for any other number. findLastIndex returns the index of the last array element for which the function returns true.

Already available in recent versions of the main browsers (06/06/2023).

What about the future?

As things stand, it looks like the syntax isn't going to change. Don't worry about your code not working on runtime 😂😂. ES6 is still supported and I would highly encourage you to learn & master ES6.

You can checkout these FREE resources down below:

  1. ECMAScript6 Learning (GitHub repo)

  2. Learn Modern JavaScript in 1 Hour (CodeWithMosh Youtube)

  3. ES6 Arrow Functions explained(WebDev Simplified) - I highly recommend this syntax, especially for writing JS Functions (Youtube)

  4. 5 JavaScript concepts you have to know by James Q Quick (Youtube)

If you feel like it has been a while since you last wrote a Javascript code, you can take the refresher course offered by Scrimba.

Conclusion

As we conclude this unwrapping of JavaScript in 2023, it's evident that the language has not just changed; it has been improved. The journey of JavaScript continues, offering a dynamic and robust environment for developers worldwide.
There have been remarkable updates to JS libraries and Frameworks. JavaScript is a very large ecosystem.

Cheers to a year of progress and innovation in the world of JavaScript programming! 🚀🌐✨