what all that means later.
What it isn’t
What it is
You’ve likely seen this in action if you’ve ever attempted to register for a website, entered a username, and immediately received feedback that the username you’ve entered is already taken by someone else (see the picture below).
Like CSS, you can embed a script right in a document or keep it in an external file and link it to the page. Both methods use the script element.
To embed a script on a page, just add the code as the content of a script element:
The other method uses the src attribute to point to a script file (with a .js suffix) by its URL. In this case, the script element has no content.
The advantage to external scripts is that you can apply the same script to multiple pages (the same benefit external style sheets offer). The downside, of course, is that each external script requires an additional HTTP request of the server, which slows down performance.
Call: +234 706 883 3966
The script element go anywhere in the document, but the most common places for scripts are in the head of the document and at the very end of the body. It is recommended that you don’t sprinkle them throughout the document,
because they would be difficult to find and maintain.
For most scripts, the end of the document, just before the </body> tag, is the preferred placement because the browser will be done parsing the document and its DOM structure. Consequently, that information will be ready and available by the time it gets to the scripts and they can execute faster. In addition, the script download and execution blocks the rendering of the page, so moving the script to the bottom improves the perceived performance. However, in some cases, you might want your script to do something before the body completely loads, so putting it in the head will result in better performance.
“MYVariable” will be treated as three different objects. Also, whitespace such as tabs and spaces are ignored, unless they’re part of a string of text and enclosed in quotes.
A script is made up of a series of statements. A statement is a command that tells the browser what to do. Here is a simple statement that makes the browser display an alert with the phrase “Thank you.”
There are two methods of using comments. For single-line comments, use two slash characters (//) at the beginning of the line. You can put singleline comments on the same line as a statement, as long as it comes after the statement. It does not need to be closed, as a line break effectively closes it.
// This is a single-line comment.
Multiple-line comments use the same syntax that you’ve seen in CSS. Everything within the /* */ characters is ignored by the browser. You can use it to “comment out” notes and even chunks of the script when troubleshooting.
/* This is a multi-line comment. Anything between these sets of characters will be completely ignored when the script is executed.
This form of comment needs to be closed. */
We’ll be using the single-line comment notation to add short explanations to example code, and we’ll make use of the alert() function we saw earlier (in the first picture above) so we can quickly view the results of our work.
We will recommend some ebooks and video clips that will teach you indepth.