Example: Remove the "//" in the script in the head tag and place them in front of the other JavaScript line.
Scripts can also be placed in external files and referenced:
JavaScript provides different methods to "print" something on the screen.
Operation | Syntax |
---|---|
Addition | x + y |
Subtraction | x - y |
Multiplication | x * y |
Division | x / y |
Modulo | x % y |
Postfix Increment | x++ |
Postfix Decrement | x-- |
Prefix Increment | ++x |
Prefix Decrement | --x |
Equal | x == y |
Unequal | x != y |
Greater than | x > y |
Greater than or equal | x >= y |
Less than | x < y |
Less than or equal | x <= y |
Logical and | x && y |
Logical or | x || y |
Binary and | x & y |
Binary or | x | y |
Binary xor | x ^ y |
Binary not | x ~ y |
Binary shift left | x << 2 |
Binary shift right | x >> 2 |
Assignments | |
x = 2 | |
x += 2 | |
x -= 2 | |
x *= 2 | |
x /= 2 | |
x %= 2 | |
x <<= 2 | |
x >>= 2 | |
x &= y | |
x |= y | |
x ^= y |
if:
switch:
for loop:
while loop:
do...while loop:
Caution: Objects are addressed by reference, not by value: This is because they are mutable. In contrast, primitive datatypes are not mutable.
Additional properties or methods can be added to the constructor after the declaration via the prototype property.
Inheritance can be implemented via the call method.