Sitemap

JS Hacks

Nov 5, 2020

--

Here are sweet some JS hacks and tips for developers for optimizing Javascript to improve JS performance and improve execution time without affecting server resources.

Q1. String replace function

The String.replace() function allows you to replace strings using String and Regex.

var string = "login login"; 
console.log(string.replace("in", "out"));
console.log(string.replace(/in/g, "out"));

Q2. Convert to a floating number

Use

~~ (math.random*100)

Instead of

math.round(math.random*100)

Q3. Use splice

myLove = ["a", "b", "c", "d"] 
myLove.splice(0, 2) ["a", "b"]

Result: myLove ["c", "d"]

--

--

Noman
Noman

Written by Noman

If passion drives you, let reason hold the reins.

No responses yet