The Remainder Operator in JavaScript | Modulo %

preview_player
Показать описание
The Remainder Operator (%) in JavaScript allows you to find the remainder of a division of two numbers - much similar to the modulo operator in many other languages. It can be used for the same purpose of finding the remainder as it uses the built in modulo function.

It is also extremely useful for limiting a large number (or converting it) into a smaller one with a maximum you specify. For example if you wanted to reduce 500 down to a maximum of 7, you can do this easily using the remainder operator.

In this video I take you through a basic example of the operator as well as it's uses to limit a number down.

For your reference, check this out:

Follow me on Twitter @dcode!

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

This is the first video I've seen that introduces the concept of reducing a large number to a smaller one. I've only seen modulo being used to determine odd or even numbers. Thank you!

AndHunt
Автор

You're the best

Whenever there's something I need to know in JS, you're always the first person that comes on my mind...

Thanks for the great tutorials

starterdev
Автор

Thanks! the remainder operator (%) is very useful. And you explain it very well.

ProgrammingNote.-bznq
Автор

Came across the code below and your explanation @1:18 was all I needed to understand what was happening:

```javascript
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var labelIndex = 0;

label = labels[labelIndex++ % labels.length];
```

Nice work!

luciusrex
Автор

Nice tutorial but too advanced for beginners. I think you should have two videos on this.

patfoiloofficial
Автор

keep on making videos, you're awesome!

RainOnline
Автор

Nice and informative video. Thank you.

vonline
Автор

Red john sound like a fiction serial killer. Nice lesson bro

bboyjojo
Автор

How do you explain these remainders?

A) 1 % 2 // 1

B) 2 % 3 // 2

darith
Автор

Hey there! I'm running into an issue with Visual Studio Code.
I cant run the console log for some reason with the terminal.
It says that node isnt recognized, and when i manually enter the path to the index save, it gives me a syntax error.. any clue why?

joelnyberg
Автор

I couldnt understand the logic behind! still lost 😵

victorartb
Автор

just watched a video for idiots and cant understand this concept. would be lovely to see this done in long form math to really understand the magic that is happening here. saying to divide something and you do it on a calculator and it doesnt come out the same as this. no amount of math does. so are we not doing math in the traditional sense?

DeathBeach
Автор

o fuck i thought it was just division this whole time and couldnt figure out why it was acting weird lool

encapsule
Автор

i understand how % works but i don't get how you got a color based on a name. please someone explain

Phill
Автор

that sure is one loud keyboard. sheesh

dilluminatilair
Автор

Hi, math idiot here. Can anyone explain why dividing 5 by 2 gives the answer of 2.5 but instead of the % operator returning 5 it returns 1?

XFunkWizardX
visit shbcf.ru