Introduction to JavaScript

post-thumb

Javascript (JS) is a dynamic computer programming language. Javascript is embedded or integrated into an HTML.

Javascript was first known as Mocha, and then called Livescript, but Netscape changed its name to Javascript because of the popularity of Java at the time. Javascript debuted in Netscape 2.0 in 1995 under the name Livescript. Many people are still confused Java and Javascript is one. But in reality, these two languages are completely different, both conceptual and design.

What is Javascript?

Javascript is defined as follows:

  • Javascript is a scripting language.
  • Javascript is a lightweight programming language.
  • Javascript is an interpreted language (that is, execution scripts without preliminaries)
  • Javascript is often embedded directly into HTML page.
  • Javascript is designed to add interactivity to HTML pages.

Why use Javascript?

Javascript is one of three languages used by all web developers: HTML, CSS, JS.

Advantage.
  • Interact less with the server.
  • Immediate feedback to customers.
  • Compatible with increased users.
  • Richer interface.
Disadvantages.

We can not think of JavaScript as a full-fledged programming language. It lacks the following important features:

  • Client-side JavaScript does not allow reading and writing of files for security reasons.
  • JavaScript is not used for network applications because there is no support.
  • JavaScript does not have any multi-threading or multi-processor capabilities.

Javascript structure?

Rule

Similar to other languages, Javascript also has syntax rules like:

  • Uppercase, lowercase.
  • Long pairs of open and close symbols such as {}, ().
  • Use extra white space, or tabs, which makes it easy to read or edit script files.
  • Use comment lines to make notes about the script’s function and creation time.
Grammar

Javascript is a set of statements that are made up of keywords, operators, and identifiers sorted in the order that the Javascript interpreter is in most browsers can understand. The statement can be long, but most are not too complicated, even if set programmers use another programming language.

Javascript position in the web page.

There are three ways to embed Javascript into HTML:

  • Embed the Javascript into the HTML file using the <script> </script> tag.
  • Write Javascript in a separate .js file and link to the HTML file using the link tag.
  • Write javascript right in the HTML tag

Write JS in the same HTML. using the <script> tag.

In the HTML page, the JS code must be placed in the <script> </script> tag.

EX:

Put the script in <head></head>

Below is a script placed in the <head> tag. The <script></script> tag is a function that replaces text.

EX:

Put script in <body> </ body>

Below is a script placed in the <body> tag. The <script> </ script> tag is a function that replaces text similar to the example above.

EX:

Put script in <footer></footer>

Same as put in <head></head> and <body></body>

Write JS in a separate file.

The Script can be written in an external file.

We write the script in a separate file when the same code is used in multiple places, this file has the .js extension.

To embed this file into HTML, we set the path and filename in the src (source) attribute of the <script> tag:

EX:

The main.js file is written as follows:

EX:

Advantages of placing JS code in a separate file:

  • Splitting HTML clearly with JS code.
  • Easy to read, easy to upgrade, easy to manage.
  • Accelerate page loads.
Write javascript right in the HTML tag

Call the function right in the HTML tag. For this we can write the js function in the <script> </ script> tag in the HTML file, or we can also write the function in a separate .js file and then call it.

EX:

Javascript, how it works?
  • Browser load page.
  • Browser checks the JS code on the web is yes or no.
  • If yes, the browser will forward the JS code to the interpreter.
  • Interpreter process and execute JS code.
  • The code may affect the components of the web page.
  • Browser shows all web content.

Hope it’s useful for you!

Suggested Articles

Let's talk.