whez9a
Last Updated: February 25, 2016
·
1.339K
· zonetti

JavaScript: Floor a number like a boss

It's not semantic, but it's interesting.

var test = 2.6;

console.log(~~test); // 2
console.log(test | 0); // 2

OBS: It's not safe either. (Thanks @mlb)

~~9999999999.3; // 1410065407

5 Responses
Add your response

5097

this awesome. must be a bug!?! :-)

over 1 year ago ·
5102
5123

Be careful with this, thought :

~~9999999999.3
// 1410065407
over 1 year ago ·
5129

@mlb Well observed.

Thanks for the warning.

over 1 year ago ·
5162

Completely pointless but awesome.

over 1 year ago ·