Javascript 1
Javascript 1
Multiline Comment
Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored by JavaScript.
This example uses a multi-line comment (a comment block) to explain the code:
Example
/*
The code below will change
the heading with id = "myH"
and the paragraph with id = "myP"
in my web page:
*/
document.getElementById("myH").innerHTML = "My First
Page";
document.getElementById("myP").innerHTML = "My first
paragraph.";
JavaScript Variables
Variables are containers for storing data values. All variables are declared by var
keyword not need to define data type. After the declaration, the variable has no
value. (Technically it has the value of undefined). To assign a value to the variable,
use the equal sign:
All JavaScript variables must be identified with unique names. These unique
names are called identifiers. Identifiers can be short names (like x and y) or more
descriptive names (age, sum, totalVolume).
The general rules for constructing names for variables (unique identifiers) are:
Names can contain letters, digits, underscores, and dollar signs.
Names must begin with a letter
Names can also begin with $ and _ (but we will not use it in this tutorial)
Names are case sensitive (y and Y are different variables)
Reserved words (like JavaScript keywords) cannot be used as names
JavaScript Operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (Remainder)
++ Increment
-- Decrement
JavaScript Assignment Operators
Assignment operators assign values to JavaScript variables.
Operator Example Same As
= x=y x=y
+= x += y x=x+y
-= x -= y x=x-y
*= x *= y x=x*y
/= x /= y x=x/y
%= x %= y x=x%y
== equal to
!= not equal
|| logical or
! logical not