Divide Assignment Operator
Basic Syntax of Divide Assignment Opetator
First, we declare a variable num using let keyword and assign a number 10 to it.
let num = 10;
Now, we use the divide assignment and print the value at the same time with the help of console log.
console.log(num /= 2); // output => 🧐 ? console.log(num /= 0); // output => 🧐 ?
let num = 10; console.log(num /= 2); // output => 🧐 ? console.log(num /= 0); // output => 🧐 ? // Made with ❤️, by @jsstartup
Now, you know the answer is 5, Infinity. But why the second output is Infinity. Let me explain.
So, for the first console log output, it’s clear that num is divide by 2 and output value assignment to num. That’s why the output is 5.
Now, that’s an obvious output that whenever a value is divided by 0 then it leads to Infinity.
At last, That’s why we get an answer “5, Infinity“.
Let me know in the comment section, what you think about it.
I hope you understand the concept and logic behind it.
But wait, i have something more for you –
- JS Quiz – can array have the size method like a set
- JS Quiz – access JSON string value is possible
And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page
If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.