. Input taken from user using window prompt gets stored as string
To convert that string into integer, we can use, parseInt() function.
var num_var = parseInt (str_var)
Just like C, we can give value to a variable while declaration and can also initiate multiple variables using commas
var num = 23 ;
var str = “wow” ;
var var1, var2, var3 ;
. If-else conditional statement is just like C
. Associativity of most operators is left to right, except assignment operator (= += -= *= /= and %= ). [Exactly like C. So, pre-increment (++x), ternary operator (? :) follows R to L order, just like C.]
. Increment or Decrement operator can only be applied to lvalue expressions (left-hand-side expression i.e. A variable or expression that can appear on the left side of an assignment operation.)
x+1 = x+2 ; // this is not valid
++(x+1) // therefore, it will be not valid.
(x+1)++ // and neither this will be valid
. Do not add spaces between <= or >=
> = //wrong
. Units for font sizes:
px = static measurement (1px = 1/96th of an inch)
pt = static measurement (1pt = 1/72nd of an inch)(So, 16px = 12pt)
ex = relative measurement wrt size of letter ‘x’
Example, in p tag, size of x is suppose 16pixels, than 1.5ex will represent 24pixels
. Like in C, we can define counter variable inside Condition Bracket of If statement.
. As in C, even if we dont initialise or implement condition or mark increment/dec… even then, we have to put two semi colons inside for’s brackets.
for (int i; ; )
/* this is working loop, where
initial variable gets the value 0,
loops till infinity,
and increment should set to 1
(although in my checking, the increment didnt set itself to 1. It was 0. i.e. no increment just 000...)*/
. In a while or for loop, since the incrementing or decrementing takes place at the end, so it doesn’t depend much whether we use post or pre.
Authors: P.J. Deitel and H.M. Deitel