Last Updated: February 25, 2016
·
1.556K
· creartinc

JavaScript's Modulo

Introduction

Hey what's up people since I signed up here, I would like to share this kinda tip about a mathematic this called "modulo". Which is the remainder of division using the % symbol, known as the modulus operator.

Example

And it could be used in the following function for example:

Use the

var isOdd = function (n) { if (n % 2 === 0) { return false; } else { return true; } };.

2 Responses
Add your response

var isOdd = function (n) { return !!(n % 2); };

I think it's easier :)

over 1 year ago ·

@avenger7x just saying ;)

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside