Introduction

JavaScript is one of the powerful programming languages in software development. You can do many things with it such as web apps, mobile apps, games, or even AI and machine learning. You just need to be good at it because every year new useful features are being released in ES versions. However, as a developer, you also need to be fast at writing code because you will have more other tasks that are important than just writing code.

In this article, we will discover some useful JavaScript tips or techniques to speed up your coding. Let’s get right into it.

1. Type conversion

In JavaScript, to convert a string to a number, we use the method parseInt() . But there is also an easy way to do that without using parseInt.

We can achieve the same result just by using the unary operator + at the beginning of the string.

Have a look at the examples below:

Normal way:

let age = "23";
console.log(typeof age); //string
console.log(typeof parseInt(age)); //number

Easy way:

let age = "23";
console.log(typeof age); //string
console.log(typeof +age); //number

You can also convert a number to a string just by concatenating the number with an empty string.

Here is an example:

let age = 19 + "";

console.log(typeof age); //string

As you can see, you can easily convert a number to a string with this technique.

#javascript #javascript-tips #coding

5 Useful JavaScript Tips to Speed Up Your Coding
1.40 GEEK