JavaScript is used in billions of Web pages to add functionality, validate forms, communicate with the server, and much more.
JavaScript is easy to learn.
JavaScript Example
My First Web Page
This is a paragraph.
Try it yourself »
Click on the "Try it yourself" button to see how it works
What is JavaScript?
JavaScript is a scripting language
A scripting language is a lightweight programming language
A JavaScript consists of lines of executable computer code
A JavaScript is usually embedded directly into HTML pages
JavaScript was designed to add interactivity to HTML pages
JavaScript is free. Everyone can use JavaScript without a license
Client-side Scripting
JavaScript is about "programming" the behavior of a browser. This is called client-side scripting (or browser scripting).
Server-side scripting is about "programming" the behavior of the server (see the Web
ASP/PHP chapter).
What can a JavaScript Do?
JavaScript gives HTML designers a programming tool - JavaScript is a scripting language with a
very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages
JavaScript can react to events - A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user
clicks on an HTML element
JavaScript can be used to validate data - A JavaScript can be used to validate form data before it is submitted to a server. This saves the
server from extra processing
JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect the visitor's browser, and load another page specifically designed for that browser
JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve information on the visitor's computer
JavaScript can read/write/modify HTML elements - A JavaScript can read and change the content of an HTML element
JavaScript uses the HTML DOM to access the elements of a web page
What is the HTML DOM?
The HTML DOM defines a standard way for accessing and manipulating HTML documents.
The DOM presents an HTML document as a tree-structure: