Skip to main content

The syntax of the JavaScript language

Each programming language has very specific rules to follow and the syntax of the JavaScript language makes no exceptions; so if you want to learn how to program for the Web "client-side", you have to write the code correctly, otherwise, it cannot be interpreted by the Browser. JavaScript is a scripting language that makes a Web page dynamic; the script code must be inserted inside the HTML tags allowing the Browser to interpret it. The processing phase is carried out locally and not by the server, using the power of the PC; this as you can guess is more advantageous.

Introduction to JavaScript

Learning the syntax of JavaScript is the first step in working with the elements of the HTML language via ID; exploiting the objects of the DOM (Data Object Model) in the Browser. JavaScript allows us to make a web page interactive and dynamic but in detail, we can do:
  • Mathematical calculations.
  • Change the graphic aspects of a web page in real-time.
  • Check the data in a form before it is sent to the server.
  • Process functions based on mouse events such as clicks and moves.
  • Create libraries and frameworks.
These are just some of the things you can do with the client-side JavaScript language.

The syntax of the JavaScript language

The syntax of the JavaScript language requires that all the code is inserted inside the script tags; that of opening and closing, at any point of the body or in the Tag head. Let's go into detail now to refine those syntactic aspects that often mislead when writing JavaScript code.

String object, variables and data types in JavaScript

A variable must be declared with the Keyword Var, followed by the name first and then by the value; with a semicolon (;) at the end. The interpreter automatically distinguishes the type of data. The floating-point is replaced by a period for decimal numbers, and as for the strings they must be enclosed in double-quotes (") or single (') but the string type (sequence of characters) in JavaScript is defined as an object similar to Java.

Syntax of the JavaScript language
Variable in JavaScript

Function in JavaScript

Functions are declared like this: (function, name to be assigned, empty round brackets or with attributes; followed by curly brackets, which are used to contain the instructions to be executed when they are called in the code.

Syntax of the JavaScript language
JavaScript function

Vectors in JavaScript

Arrays (vectors) are used to group multiple values and must be enclosed in square brackets; while between braces for object notation (associative pairs of keys plus value). In JavaScript, Arrays are a special type of object and the elements that compose it always start from zero and not from one! This type of numerical reference then allows us to take them individually even for a simple screen print. The keyword new allows you to create new Arrays with round brackets.

Vector in JavaScript language
Array in JavaScript

Expressions in JavaScript

Algebraic operations in JavaScript are handled by round brackets that replace braces and brackets; the precedence in the expressions are obtained starting from the most internal to the external ones; while as regards the arithmetic operators, the same rules that you learned at school apply.

Comment the code in JavaScript

Web programmers add notes to comment on blocks of code; a logical reference of a given block of code even after some time. The code is commented out by typing the forward-slash (//) character twice for a single line; while only once followed by the asterisk symbol for multiple lines with this syntax (/ * * /).

Notice

Before closing this JavaScript syntax guide; keep in mind the language is case sensitive and therefore is case sensitive when creating variables and functions! Also, avoid special characters and numbers because they are not allowed; only the Underscore (_) character is. Finally, be aware that JavaScript code scripts can also be recalled externally like style sheets.

Comments

Popular posts from this blog

Breadcrumbs in Notable Blogger theme

The modern themes available in Blogger are suitable for mobile devices; this is important in terms of indexing but Blogger not support breadcrumb of schema.org by default. If you add a few lines of code you can greatly improve your SEO and therefore your ranking in Google Search. I create a personal breadcrumb solution; if you have installed a responsive theme like mine in this article I explain how to add Breadcrumbs in Notable Blogger theme. How to add breadcrumbs in Notable Blogger theme First thing create a backup of you theme for security reasons You can add breadcrumbs in JSON-LD format or as following micro-data solution: Open your Blogger Dashboard Click on Theme >> Download a Backup for security reason Copy this code  <div class='post-body-container'>   Click Ctr+F and past the copied code then click Enter You will find this tag 1 time. Breadcrumbs in Notable Blogger theme Now copy the following code and past it below the tag : <b:if cond='data:view.

How to insert JavaScript into web pages

You have learned everything there is to know about HTML and CSS to start building your static website and now you would like to make it dynamic but you don't know how to insert JavaScript into web pages; right? Don't worry! Inserting the scripts into html files is really a breeze. If you read this article, in the next five minutes you will discover all the methods for inserting JavaScript into html files. How to insert JavaScript into HTML file JavaScript need HTML file to work.  Like CSS all methods of inserting JavaScript into a Web Page can be divided into two sections; add the scripts inside the TAG of  HTML file or by calling them externally. In detail we can insert JavaScript: Directly into Body of the HTML file. In the Head Tag and recall it in the body. With a relative or absolute external reference. Insert JavaScript into HTML file We will see an example of how to insert JavaScript shortly but first let's focus on when it is useful to do an explicit or implicit

Object cache problem of the AMP plugin for WordPress

If you are looking for one solution to the fix object cache problem of the WordPress AMP plugin displayed in dashboard from Site health; in this article I will show You how to do this in five minutes. Usually this situation arises when the installed theme is non an official theme and You have not cache plugin installed; anyway don't worry! We will solve the problem in a moment. Object cache problem of the AMP plugin for WordPress Why is important to enable persistent object cache for AMP  Accelerate mobile page (AMP), is latest technology of the Web. An amp page load very fast compared to to a standard Web page and Google search engine like very much this; so you can improve the ranking of your site and get more mobile users traffic. Persistent object cache If persistent object cache is enabled, WordPress work better; the images and files as CSS will loaded more fast. Every WordPress Hosting have a cache service, otherwise it would be very strange and I recommend that you consider