Concantenating strings in Javascript -


new javascript. code below, looking @ 2nd paragraph in particular...if var str = "sting equality test..." + stra, why 2nd, 3rd lines etc not output same output plus own line?

edit sorry not explaining - wondering why code (once have cleaned up) doesn't produce first line (of 2nd paragraph) repeated, plus whatever state in 2nd , 3rd lines etc. don;t need to, exercise, don't understand. seems though should

function init() { var stra = "javascript" === "javascript" ; var strb = "javascript" === "javascript" ; var flt = 7.5 === 7.5 ; var inta = 8 !== 8 ; var intb = 24 > 12 ; var intc = 24 < 12 ; var intd = 24 <= 24 ;  var str = "string equality test: " + stra ; str += "<br>string equality test 2: " + strb ; str += "<br>float equality test: " ; + strc ; str += "<br>integer inequality test: " + inta ; str += "<br>greater test: " + intb ; str += "<br>less test: " + intc ; str += "<br>less than/equal test: " + intd ;  document.getelementbyid( "panel" ).innerhtml = str ;    } document.addeventlistener("domcontentloaded" , init , false) ; 

so output isas follows;

string equality test: false string equality test 2: true float equality test: true integer inequality test: false greater test: true less test: false less than/equal test: true

this correct, don't understand how following isnt outputted because surely adding each line var str, "string equakity test: false

 string equality test: false string equality test: false string equality test 2: true string equality test: false float equality test: true string equality test: false integer inequality test: false string equality test: false greater test: true string equality test: false less test: false string equality test: false less than/equal test: true 

i don't understand how following isnt outputted because surely adding each line var str, "string equakity test: false"

no, time str equal "string equality test: false" after first line. each line modifies str variable adding whatever became after line before. after first line:

var str = "string equality test: " + stra ; 

...the variable str equal to

"string equality test: false" 

then after second line:

str += "<br>string equality test 2: " + strb ; 

...the variable str equal to

"string equality test: false<br>string equality test 2:" 

the third line has error, assuming remove semicolon , fix variable name:

str += "<br>float equality test: " ; + strc ; // should str += "<br>float equality test: " + flt; 

...then variable str equal to

"string equality test: false<br>string equality test 2: true<br>float equality test: true" 

...and forth.

you can see if add console.log(str); statement in between each line , open browser's console before running code. shown here: http://jsfiddle.net/mfky9/


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -