Forem

Cover image for Operadores Aritméticos (Parte 1)
ananopaisdojavascript
ananopaisdojavascript

Posted on • Edited on

1

Operadores Aritméticos (Parte 1)

Usamos operadores aritméticos para... fazer cálculos (duh de novo!). Os operadores aritméticos são:

/* + adição */
/* - subtração */
/* * multiplicação */
/* / divisão */
/* % módulo */
Enter fullscreen mode Exit fullscreen mode

Epa... o que é esse %?!?!

Para ficar um pouquinho mais fácil, % é o resto da divisão. Por exemplo, o resto da divisão de 5 por 2 é igual a 1, portanto ficaria representado assim:

5 % 2 = 1; // 1 é o resto da divisão
Enter fullscreen mode Exit fullscreen mode

Mas temos outros tipos de operadores...

Temos também o incremento ++ e o decremento -- que indicam adicionar 1 ou diminuir em 1.

i++; // O mesmo que i + 1
i--; // O mesmo que i - 1
Enter fullscreen mode Exit fullscreen mode

Podemos usar esses operadores junto com o = para criarmos operadores de atribuição.

a += b; // O mesmo que a = a + b
a -= b; // O mesmo que a = a - b
a *= b; // O mesmo que a = a * b
a /= b; // O mesmo que a = a / b
Enter fullscreen mode Exit fullscreen mode

E aí? Gostaram? Até a próxima anotação!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay