JavaScript Examples

Examples Explained

What can JavaScript do?

Where to Insert JavaScript

JavaScript Output

JavaScript Syntax

JavaScript Statements

JavaScript Comments

JavaScript Variables

JavaScript Arithmetic

JavaScript Assignment

JavaScript String Concatenation

JavaScript Data Types

JavaScript Objects

JavaScript Functions

JavaScript Events

JavaScript Strings

JavaScript Numbers

Numbers can be written with or without decimals Extra large or extra small numbers can be written with exponent notation 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 Adding two numbers results in a new number Adding two numeric strings results in a concatenated string Adding a number and a numeric string also results in a concatenated string Adding a numeric string and a number also results in a concatenated string Common mistake when adding strings and numbers 1 Common mistake when adding strings and numbers 2 JavaScript will try to convert strings to numbers when dividing JavaScript will try to convert strings to numbers when multiplying JavaScript will try to convert strings to numbers when subtracting JavaScript will NOT convert strings to numbers when adding A number divided by a string is NaN (Not a Number) A number divided by a numeric string is a number The global JavaScript function isNaN() returns if a value is a number Using NaN in a mathematical operation will always return NaN Using NaN in a mathematical string operation will concatenate NaN NaN (Not a Number) is a number (Yes! typeof NaN returns number) Infinity is returned if you calculate a number outside the largest possible number Division by zero also generates Infinity Infinity is a number (typeof Infinity returns number) Constants, preceded by 0x, are interpreted as hexadecimal The toString() method can output numbers as hex, octal, and binary Numbers can be objects Numbers and objects cannot be safely compared Objects and objects cannot be safely compared

JavaScript Number Methods

JavaScript Maths

JavaScript Random

JavaScript Dates

JavaScript Arrays

JavaScript Array Methods

JavaScript Array Sort

JavaScript Array Iteration

JavaScript Type Conversion

JavaScript Booleans

JavaScript Comparisons

JavaScript Conditionals

JavaScript Loops

JavaScript Error Handling

JavaScript Regular Expressions

JavaScript Objects

JavaScript Object Properties

JSON Objects

JSON Arrays

JSON Parse

JSON Stringify

JSON PHP

JSON HTML

JSON JSONP