Doubt of beginner in javascript

Asked

Viewed 47 times

-1

I have a question and code follows below:

var j = 1928182;

while (j > 50) {
    console.log(j);
    j /= 5;
}

As the code says, while j is greater than 50, it will divide by 5, right? Why if you put the console.log before the condition of j be divided by 5, it appears the same way the result? With everything in this language is like this?

  • @rd_1999 for being a sequential and interpreted language. On this.log() console of yours, the output result would be the value (number) being divided by 50.

  • is that for example, CSS uses type in cascade format right? I’m asking if you don’t need to sort it out "in an order", because I gave the command to appear on the console, before J split by 5

1 answer

1


If I understand your doubt, while will rotate several times, while the j is GREATER than 50, as it is divided this number will decrease, when it is equal to or less than 50 o while will stop.

The console.log is to know the current value of the j each cycle of while, for example, without the while you would have something like:

j = 1928182;
console.log(j);
j /= 5;
console.log(j);
j /= 5;
console.log(j);
j /= 5;
console.log(j);
j /= 5;
console.log(j);
j /= 5;
console.log(j);
j /= 5;
console.log(j);
j /= 5;
console.log(j);
j /= 5;

It would be similar to doing this:

j = 1928182;

while (j > 50) {
    console.log(j);
    j /= 5;
}

The same results were shown, i.e. console.log is to know what value will be divided, probably to analyze the process step by step.

Recalling that the console.log is a function to be used with the tools:

  • Chrome Devtools
  • Microsoft Developer tools
  • Firefox Developer Tools

and similar (such as browser-dependent javascript engine console)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.