Javascript and Java are alike each other, including control statements and String object.
All control statements such as if, for, while, swith in java also emerge in javascript .
Code Example:
var lines = new Array("hello", "world"); for(var i = 0; i < lines.length; i++){ document.write(lines[i] + "<br/>"); } equals to: for( line in lines){ docment.write(line + "<br/>"); }
Javascript is a weaky typed language that implies variables maybe equal even their types are not same.code example:
1. var s="the " + 1 + "st". int variable is converted into string automaticly. 2. weaky typed equals '==' function fun(){ if("3.0"==3){ document.write("string 3.0 equals int 3:" + true); // string variable can concatenate boolean variable. }else{ document.write(false); } };
type convention parseInt/parseFloat.
constant const PI=3.14