Académique Documents
Professionnel Documents
Culture Documents
Example
<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>
External JavaScript
Scripts can also be placed in external files:
myScript.js
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
Example
<script src="myScript.js"></script>
Example
carName = "Volvo";
var person = "John Doe", price = 200;
Example
carName = "Volvo";
var carName;
string
number
boolean
object
function
Object
Date
Array
null
undefined
JavaScript Operators
Operator
Description
Subtraction
Multiplication
Division
Modulus
++
Increment
--
Decrement
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
Description
length
indexOf ( str )
Returns the position of the first occurrence of the specified text (str) in a string
lastIndexOf ( str )
Returns the position of the last occurrence of the specified text (str) in a string
substr ( start, L )
Returns a part from a string that contains L characters starting from start
replace ( S, R )
toUpperCase ()
toLowerCase ()
charAt ( pos )
split ( delimiter )
Description
toString ()
Number (str)
parseFloat (str)
Returns the first number in str as integer or float, returns NaN if no number has
been found at the beginning
parseInt ( str )
Returns the first number in str as integer, returns NaN if no integer has been
found at the beginning
Math.abs ( X )
Math.round ( X )
Math.ceil ( X )
Math.floor ( X )
Math.min ( a, b, c, d, )
Math.max ( a, b, c, d, )