Javascript Basics Part II
Statements
break
for
switch
throw
try
with
For statement
Switch statement
- The switch value can be a string. Not restricted to integer
- The cast statements can be expressions, not just constants
Throw statement
Try statement
- Because we don’t have classes, we just have one
catch
clause. There cannot be multiple catch clauses. - The javascript implementation can produce these exception names:
Error
EvalError
RangeError
SyntaxError
TypeError
URIError
With statement
- Ambiguous and error prone, don’t use it.
Either o.foo = null;
or foo = null;
depending on if foo is a global variable
Function statement
Var statement
- Types are not specified
- Initial values are optional
Scope
- Blocks do not have scopes, only function has scopes.
- Because of laziness while writing the compiler :)
- This is a mistake in language
Return statement
return expression;
Or
return;
- If there is no expression, then the return value is
undefined
- Exception in constructors, return value is
this