



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




1
Avoid $ as it is commonly used in external frameworks (JQuery)
salesTaxRate, firstName
// for single line /* */ for multi-line
2
Scripting rules of thumb
Postel's Law
if (condition) { ddo this; hi } Opening (or closing) brace goes on line with the statement that controls access to the code block.
Variables and typing
Variables are not explicitly typed, and type may be
changed implicitly through assignment.
''var' placed in front of identifier to denote a variable ' l d i f t f id tifi t d t i bl
declaration.
4
Type conversion functions
true: boolean true, nonempty string, nonzero number, any object f lfalse: boolean false, empty string, 0, NaN, null, b l f l t t i 0 N N ll undefined.
boolean true returns 1, false returns 0. if val is numeric, returns val. if val is undefined, returns NaN. null string returns 0.ll t i t 0 String containing a number ('123'), returns that number. String containing text, returns NaN.
Type conversion functions
If first non-whitespace character in val is not numeric or string is null, returns NaN. CContinues parsing val until reaches end or a non-numeric ti i l til h d i value. Returns that outcome. If numeric substring begins 0x, interpreted as hexadecimal. If begins with 0, interpreted as octal. Favored over Number since returns NaN on a null string val instead of 0. An optional second parameter can specify the base ofAn optional second parameter can specify the base of val. Returned value is always base 10. http://einstein.etsu.edu/~pittares/CSCI3110/examples/2-3.htm
5
Type conversion functions
Similar to parseInt, except
. is a valid part of a number, but can only occur once. Zeros at the beginning are ignoredZeros at the beginning are ignored. If val in hexadecimal form ("0x…") 0 is returned. If val in scientific notation form, float equivalent is returned. (2.7845e10)
If val is null or undefined, "null" or "undefined" returned. If val is number, optional parameter can specify base ofIf val is number, optional parameter can specify base of output. var x = 10; var y = x.toString(2);
In class practice