javascript - Working of increment operator and document.write function -


as know:

i++ -> use first , increment it's value

++i -> increment first , use i's new value

but in code below different

var n=5; for(i=n;i>=1;--i) {    console.log(i);//output:5 why?     for(j=1;j<=n;++j)     {        document.write(j);     } document.write("\n"); } 

even though using predecrement operator why vaule outputs 5 on fist loop? using new line after completion of innerloop dont show .what can reason behind this?is becoz on each loop document.write() running document.open() function?if yes ,in context || conditions document.write runs document.open() function?

the ++j in for(j=1;j<=n;++j) occurs @ end of for loop after statements in loop executed there no difference in for construct between ++j , j++.

you can think of loop this:

for(j=1;j<=n;) {    document.write(j);    ++j; } 

as console.log(i);//output:5 why? question, that's because 5 initial value i assign in i=n.

as document.write('/n');, html ignores newlines. if want visible newline, use <p> or <br> or other html construct makes space. newlines ignored.

there no difference between html:

<span>this text</span> 

and html newlines in it:

<span> text </span> 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -