Let’s Write Fast JavaScript

Credit: Celesty Lee

#1 Don’t make me typecast

{
var x = '2';
var y = 5;
x = 2;
x + y;
}

Bonus: String to Number conversion

// Different ways of parsing integer/float from strings
parseFloat("100")
+"100"
// integer only
parseInt("100", 10)
"100"|0
"100" >> 0
"100" << 0
//Only works for positive numbers
"100" >>> 0

#2 Don’t re-structure objects

Don’t use delete operator

Don’t add properties later

#3 String concatenating

#4 Use The Right RegExp Method

#5 Declare & Pass Local Scoped Variables

#6 You don’t need jQuery for everything

$('input').keyup(function() {
if($(this).val() === 'blah') { ... }
});
$('input').keyup(function() {
if(this.value === 'blah') { ... }
});

Bonus Tip: Use Web Workers for Heavy Tasks

Unlisted

--

--

Software Engineer at AYLIEN. Opensource guy. Mozillian.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mahdi Dibaiee

Mahdi Dibaiee

Software Engineer at AYLIEN. Opensource guy. Mozillian.