X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript Examples II


JavaScript Numbers

Number are considered accurate only up to 15 digits
Floating point arithmetic is not always 100% accurate
But it helps to multiply and divide by 10
Constants, preceded by 0x, are interpreted as hexadecimal
The toString() method can output numbers as hex, octal, and binary
JavaScript will generate Infinity if you calculate a too large number
Division by zero generates Infinity
A number divided by a string is not a number

Numbers explained


JavaScript Arithmetics

The addition operator
The subtraction operator
The multiplication operator
The division operator
The modulus operator
The pre increment operator
The post increment operator
The pre decrement operator
The post decrement operator

Arithmetics explained


JavaScript Maths

Use Math.random() to return a random number between 0 and 1
Use Math.round() to round a number
Use Math.ceil() to round a number (up)
Use Math.floor() to round a number (down)
Use Math.floor() and random() to return a random integer
Use Math.max() to return the number with the highest value
Use Math.min() to return the number with the lowest value
Convert Celsius to Fahrenheit

Maths explained


JavaScript Dates

Use Date() to display today's date and time
Use getFullYear() display the year
Use getTime() to calculate the number of milliseconds since 1970
Use setFullYear() to set a specific date
Use toUTCString() to convert today's date (according to UTC) to a string
Use getDay() to diplay the weekday as a number
Use getDay() and an array to display the weekday as a name
Display a clock

Dates explained


JavaScript Arrays

Create an array
Join two arrays - concat()
Join three arrays - concat()
Join all elements of an array into a string - join()
Remove the last element of an array - pop()
Add new elements to the end of an array - push()
Reverse the order of the elements in an array - reverse()
Remove the first element of an array - shift()
Select elements from an array - slice()
Sort an array (alphabetically and ascending) - sort()
Sort numbers (numerically and ascending) - sort()
Sort numbers (numerically and descending) - sort()
Add an element to position 2 in an array - splice()
Convert an array to a string - toString()
Add new elements to the beginning of an array - unshift()

Arrays explained


JavaScript Type Conversion

Display the typeof all variable types
Display the constructor of all variable types
Convert a number to a string using String()
Convert a number to a string using toString()
Find out if a variable is an array
Find out if a variable is an date

Data Conversion Explained


JavaScript Booleans

Display the value of Boolean(10 > 9)
Display the value of 10 > 9
Everything with a real value is true
The Boolean value of zero is false
The Boolean value of minus zero is false
The Boolean value of an empty string is false
The Boolean value of undefined is false
The Boolean value of null is false
The Boolean value of false is false
The Boolean value of NaN is false

Booleans explained


JavaScript Comparisons

Assign 5 to x, and display the value of (x == 8)
Assign 5 to x, and display the value of (x == 5)
Assign 5 to x, and display the value of (x === 5)
Assign 5 to x, and display the value of (x === "5")
Assign 5 to x, and display the value of (x != 8)
Assign 5 to x, and display the value of (x !== 5)
Assign 5 to x, and display the value of (x !== "5")
Assign 5 to x, and display the value of (x > 8)
Assign 5 to x, and display the value of (x < 8)
Assign 5 to x, and display the value of (x >= 8)
Assign 5 to x, and display the value of (x <= 8)

Comparisons explained


JavaScript Conditionals

The if statement
The else statement
The else if statement
Random link
Switch statement

Conditionals explained


JavaScript Loops

For loop
Looping through HTML headers
While loop
Do While loop
Break a loop
Break and continue a loop
Use a for...in statement to loop through the elements of an object

Loops explained


JavaScript Error Handling

The try...catch statement
The try...catch statement with a confirm box
The onerror event

Errors explained


JavaScript Regular Expressions

Search for an expression in a string
Search for an expression and replace it

Regular Expressions Explained


JavaScript Objects

Create a direct instance of an object
Create objects using an constructor
Creating and accessing an object method
Use a for...in statement to loop through the elements of an object

Objects explained




Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook