Useful JavaScript Tips

Mohomed Rikas
2 min readApr 19, 2021

Here are 5 JavaScript tips that you probably did not know about!

1. Get the performance of your code!

Might be fun to compare the performance of two different computers, or to show off with your M1 Mac chip .

2.Converting a number to a string

It can be useful when having to deal with the data type error saying you cant sum up two variables or constants that do not have same data type.

3. Converting a string to a number

Just the vice-versa of the previous example(2). Though, keep in mind that it will work only with string numbers,as shown with the second example.

4.Replacing all occurrences of a string.

We used a regex command /g in the second example to let javaScript know that we want to do it globally, for every single occurrence of the desired word!

5.Fill an array with empty spaces.

By using this .fill() method, you can easily create an empty array just like that.This can also be done with values such as numbers or string.

--

--