8 javascript features you might have never used before - Developer Tip of the Week

8 javascript features you might have never used before - Developer Tip of the Week
Written by
Shedrack Akintayo
January 27, 2023
No items found.

JavaScript is a powerful and versatile programming language that is widely used for both front-end and back-end web development. With its constantly evolving feature set, there's always something new to discover and explore. In this article, we'll take a look at 5 JavaScript features that you might not have used before but are definitely worth checking out.

  1. The Object.getOwnPropertyDescriptors() method: This method returns an object that has the same property descriptors as the given object. It allows you to access the property descriptor of any object, including non-enumerable properties.
  1. The String.prototype.trimStart() and String.prototype.trimEnd() methods: These methods were introduced in ES2019 and they allow you to remove whitespace from the beginning and end of a string, respectively.
  1. The BigInt type: BigInt is a new numeric primitive introduced in ES2020 that represents integers with arbitrary precision. It allows you to safely work with integers larger than the maximum safe integer value of JavaScript.
  1. The globalThis property: This property was introduced in ES2020 and it gives you a way to access the global object from any context, whether it is a web page, web worker, or a Node.js script.
  1. The matchAll() method: This method was introduced in ES2020 and returns an iterator of all results matching a regular expression in a given string.
  1. Apply CSS to console using %c: A feature that is often overlooked in JavaScript is the ability to implement any CSS property onto the console. Through the use of ‘%c’, you can alter the appearance of text by changing characteristics such as colour and boldness, which is particularly useful.
  1. Efficiently Converting Float to Integer: Traditionally, the conversion of float to an integer involved the use of Math.ceil(), Math.floor() or Math.round(), however by using a bitwise OR Operator, this conversion can be simplified and sped up.
  1. The IN operator: The ‘IN’ keyword can be utilised to determine if a string or symbol property is defined in an object. This feature both reduces the amount of code required, and prevents errors when accessing private property which may be null.

In conclusion, while these lesser-known JavaScript features may not be as commonly used as some of the more well-known features, they can still provide valuable functionality and make your code more efficient and maintainable. Whether it's working with arbitrary precision integers or removing whitespace from the beginning and end of a string, these features can help you write cleaner, more expressive code and make your development experience more enjoyable. It's always worth keeping an eye out for new and lesser-known JavaScript features and experimenting with them in your own projects.