The language syntax

The language syntax is basically a means of communication. In a programming language, it's a formal way of communicating with algorithms, from both algorithms to programmer and programmer to machine. This is because a machine works on given instructions.

These instructions are meant to be written in a specific format, so that a machine could understand and compile it properly. That specific format is defined by some general rules of a programming language, known as language syntax.

A computer contains a list of instructions to be executed. Every computer language has different syntax and rules. To use different languages, we must have knowledge of their language syntax, such as the following:

  • Syntax (a set of symbols and rules)
  • Semantics (for transforming term to term)
  • Pragmatics (the particular construct of a language)

Similarly, other languages in JavaScript have a unique syntax. JavaScript is not a language of Java; these are two different languages and the syntaxes for both languages are different. JavaScript is a powerful and expressive language. JavaScript's statements are separated by a semicolon at the end.

The JavaScript language syntax is much easy for beginners who have an idea of object-oriented programming. JavaScript is contained between the <scripts>…</script> tags. These are treated as HTML tags in any web browser.

You can place your JavaScript code anywhere on your webpage, but I prefer the way of defining your script using the <head> tag. So, the structure of your script will be as follows:

<head>
  <script>
    ……………..
  </script>
</head>

Basically, the <script> tag when written writing <head> tag, tells the browser that this scripts need to be executed first when the web page loads. Although, its a good practice to include javaScript is to place it at the bottom of a web page. There are two important attributes of this script tag.

Language

The language attribute will tell which language attribute you are using; typically, it's JavaScript. It is the default value if the attribute is absent.

Type

The type attribute is the same as the preceding explanation. This is not a required attribute. Its value is set as text/javascript, which shows that this scripting language is in use.

<script language=" javascript" type="text/javascript">
  .Script code.
</script>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.3.167