Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this proper JavaScript syntax?
    text
    copied!<p>Good Saturday morning to the most helpful online community on the web! =)</p> <p>I have a few hundred lines of JavaScript that I'd like to reformat to make it easier for me to read. I thought before I went wasting half of my day, I'd ask my question here first.</p> <p>I am new to JavaScript and would like to know if my syntax below is correct?</p> <p>My original code is this:</p> <pre><code>function formfocus() { if(document.getElementById('inputida')) { document.getElementById('inputida').focus(); document.getElementById('inputida').value = ''; } else if(document.getElementById('inputidb')) { document.getElementById('inputidb').focus(); document.getElementById('inputidb').value = ''; } } function popitup(url, name, width, height) { newwindow = window.open(url, name, 'width=' + width + ',height=' + height + ',scrollbars=yes'); if(window.focus) { newwindow.focus(); } return false; } </code></pre> <p>... And I want to change the code into this (note the spacing):</p> <pre><code>function formfocus() { if ( document.getElementById( 'inputida' ) ) { document.getElementById( 'inputida' ).focus(); document.getElementById( 'inputida' ).value = ''; } else if ( document.getElementById( 'inputidb' ) ) { document.getElementById( 'inputidb' ).focus(); document.getElementById( 'inputidb' ).value = ''; } } function popitup( url, name, width, height ) { newwindow = window.open( url, name, 'width=' + width + ', height=' + height + ', scrollbars=yes' ); if ( window.focus ) { newwindow.focus(); } return false; } </code></pre> <p>The differences being:</p> <ol> <li>spacing just after the <code>'if'</code> and <code>'else if'</code> statements</li> <li>spacing around the <code>parentheses</code></li> <li>a line-feed before the opening <code>curly braces</code></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload