- Adding custom HTML elements
- Adding and editing items even after the page has loaded
- CSS modification (element style changes)
- Creating dynamic elements
- Creation and compilation of forms
- Sending and receiving data
- Saving and loading files
- File generation
- Programming in general and much more
1. In-line code
In HTML pages each element is defined by means of special tags with specific functions. The integration of JS codes within HTML pages is possible simply by defining one of these tags in any desired position.
These tags can be multiple on the same page, we can also say unlimited.
Furthermore, unlike many other HTML elements, <script> can be inserted in both <body> and <head> without particular distinction. The choice falls on the basis of needs, many scripts in fact need to be executed before rendering or loading the page to work.
In the case of secondary or manual scripts, it is possible (and recommended) to define them in the page footer, in the lowest position, in order to make the page load faster.
2. External code
The URL or path of the file in .js format must be entered in the “src “attribute. The position of the HTML tag follows the same rules of in-line writing as in the previous section.
<! DOCTYPE html>
These rules are easy to remember and we can summarize them in these points:
- Each line of code must end with a semicolon (;).
- JS is case sensitive, that is, it distinguishes between lowercase and uppercase letters (“Name” is different from “name”.
- The custom name of variables, objects and functions cannot start with a number or symbol.
- The separation of words that make up a custom value / name can be defined with the symbol “_” (underscore).
- Furthermore, custom names cannot have spaces between the words that compose them
- It is recommended to use names like my Variable or my_function for example.
- To define text strings or values, they must be enclosed in single (‘) or double (“) quotes, otherwise they will not be executed and will return errors.
- You cannot give prohibited names to variables or functions. For forbidden we mean those pre-imposed names present in the language that already have established functions such as: function, while, for, in, do, return, this etc …
Keep these concepts in mind but don’t give them too much weight, you will see everything in detail in the following articles.
Therefore pay close attention to writing the code and try to be as orderly as possible following the hierarchy of elements.
If you want to learn more, you can take a look at the “HTML & JS functions ” section of our site, you will find many useful tutorials to start programming with JS in a simple and intuitive way.
About us: Codelivly is a platform designed to help newbie developer to find the proper guide and connect to training from basics to advance .