What is Javascript and the Basis of Javascript Explained

JavaScript and Basics of Javascript

JavaScript may be a programming language (also referred to as scripting). All developers square measure at home with JavaScript to a point. From easy animations on web content to advanced interactions, we’ve all found ourselves victimization it a minimum of once.

JavaScript may be a programming language originally born for the online. Brendan Eich, the creator of JavaScript, found himself operating for web browser in 1995. The project manager assigned Brendan a on the face of it not possible task: to form a programming language that worked within the web browser Navigator browser.

Discovery

Brendan Eich formed JavaScript (originally named Mocha), that was developed in exactly ten days. The results of those ten days of development? An odd language, decorated with things that square measure themselves strange. Since that point JavaScript has become the universal language of the online, though it’s ne’er enjoyed a stellar name.

What is JavaScript used for?

As mentioned, JavaScript is a programming language for creating dynamic objects on pages or websites. With this language it is possible to alter and modify every single element on the page to our liking and without limits.

Some of the main uses of JavaScript are as follows:

  • 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
  • Notices
  • Effects
  • Animations
  • Programming in general and much more

It might be difficult to understand at first glance, but JavaScript is a powerful programming language with which it is really possible to act on any single object very easily or create whatever you have in mind. The only limit is your own knowledge.

Integrate JavaScript into web pages

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.

In fact, JavaScript lives inside web pages through the <script>… </script> tags.

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

Another method for integrating JavaScript code into an HTML page is through external files in .js format Much like CSS, you can call external JavaScript resources on a page like this:

<script type=”text/JavaScript” src=”codici.js”></script>

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.

NB In the <script> tag it is possible to add an instruction on the format defined by the “type” attribute (type =”text / JavaScript “). In the latest versions of JS it is more mandatory to indicate this instruction.

Example

Below is an example of opening the JavaScript code in an HTML page, devoid of actual useful code.

<! DOCTYPE html>

<html>

  <head>

      <script type=”text/javascript”>

            ….

      </script>

  </head>

  <body>

      <script>

            ….

      </script>

      <script type=”text/javascript” src=”codici.js”></script>

  </body>

</html> 

3. JavaScript rules

The JavaScript code to be executed correctly by browsers must respect certain rules; otherwise it will be easy to run into unpleasant errors.

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.

JavaScript is a typed language but without too many restrictions or constraints, that is, to be executed it does not need an ordered and specific structure, but is able to interpret scripts even with any errors and shortcomings, compensating the absent values ​​with those it deems most appropriate (example ‘absence of a semicolon or repetition of variables).

JavaScript is a language that executes “cascading” instructions, i.e. from first to last in order of writing on the page. Any statement executed after, if required, can overwrite a previous one.

Therefore pay close attention to writing the code and try to be as orderly as possible following the hierarchy of elements.

This was the introduction to JavaScript for the first article of our course, which as mentioned will be for beginners. Also in the next ones we will try to give detailed explanations without superfluous information, because JS like many other programming languages ​​are based a lot on constant practice.

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.

Also Check:

Happy Coding…☺️

About us: Codelivly is a platform designed to help newbie developer to find the proper guide and connect to training from basics to advance .

1 thought on “What is Javascript and the Basis of Javascript Explained”

Leave a Comment