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

JavaScript Examples I


Where to Insert JavaScript

JavaScript in <head>
JavaScript in <body>
An external JavaScript

Examples explained


JavaScript Syntax

JavaScript numbers
JavaScript strings
JavaScript expressions
JavaScript variables
JavaScript operators
JavaScript assignment

Examples explained


JavaScript Statements

JavaScript statements are commands to the browser
JavaScript code is a sequence of statements
Statements are separated with semicolon
Multiple statement on one line is allowed
JavaScript can be grouped together in code blocks
You can break a code line after an operator or a comma.
You can break text string with a backslash.
You cannot break code with a backslash.

Examples explained


JavaScript Comments

Single line comments
Single line comments at the end of a line
Multiple lines comments
Single line comment to prevent execution
Multiple lines comment to prevent execution

Examples explained


JavaScript Variables

Declare a variable, assign a value, and display
Declare variables, assign values, and display
Create variables of different types
Add two numbers
Add two strings

Examples explained


JavaScript Data Types

Declare (create) strings
Declare (create) numbers
Declare (create) an array
Declare (create) an object
Undefined and null
Use typeof to find the type of variables

Examples explained


JavaScript Objects

Create a JavaScript variable
Create a JavaScript object
Create a person object (single line)
Create a person object (multiple lines)
Access object properties using .property
Access object properties using [property]
Access a function property as a method
Access a function property as a property

Examples explained


JavaScript Functions

A simple function
A function with an argument
A function with an argument 2
A function that returns a value
A function that converts Fahrenheit to Celsius
A function call without ()

Examples explained


JavaScript Events

An onclick event changes an HTML element
An onclick event changes its own element
An onclick event calls a function

Examples explained


JavaScript Strings

Show some string examples
Find the length of a string
Find the position of the first occurrence of a text in a string - indexOf()
Search for a text in a string and return the text if found - match()
Replace characters in a string - replace()
Convert string to upper case - toUpperCase()
Convert string to lower case - toLowerCase()
Split a string into an array - split()

Examples explained



Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook