Before diving into the JavaScript language, you need to know how it will fit together with the HTML and CSS in your web pages.
These three layers form the basis of a popular approach to building web pages called progressive enhancement.
JavaScript is written in plain text, just like HTML and CSS, so you do not need any new tools to write a script. This example adds a greeting into an HTML page. The greeting changes depending on the time of day.
*When you want to use JavaScript with a web page, you use the HTML
If you look at the source code for the example you just created, you will see that the HTML is still exactly the same. ## PLACING THE SCRIPT IN THE PAGE You may see JavaScript in the HTML between opening tags (but it is better to put scripts in their own files).
In this chapter, you will start learning to read and write JavaScript. You wil l also learn how to give a web browser instructions you want it to follow.
THE LANGUAGE: SYNTAX AND GRAMMAR like any new language, there are new words to learn (the vocabulary) and rules for how these can be put together (the grammar and syntax of the language)
GIVING INSTRUCTIONS: Web browsers (and computers in general) approach tasks in a very different way than a human might. Your instructions need to reflect how computers get things done.
A script is a series of instructions that a computer can follow one-by-one. Each individual instruction or step is known as a statement. Statements should end with a semicolon.
You should write comments to explain what your code does. They help make your code easier to read and understand. This can help you and others who read your code.
MULTI-LINE COMM ENTS : To write a comment that stretches over more than one line, you use a multi-line comment, starting with the /* characters and ending with the */ characters. Anything between these characters is not processed· by the JavaScript interpreter. M ulti-line comment s are often used for descriptions of how the script works, or to prevent a section of the script from running when testing it.
SINGLE-LINE COMMENTS : In a single-line comment, anything that follows the two forward slash characters I/ on that line will not be processed by the JavaScript interpreter. Singleline comments are often used for short descriptions of what the code is doing. Good use of comments will help you if you come back to your code after several days or months. They also help those who are new to your code.