JavaScript Part-1: Introduction to JavaScript

JavaScript Part-1: Introduction to JavaScript

What is JavaScript?

Image

JavaScrpt, also known as JS for short, is a lightweight, interpreted (i.e. no need to compile) and prototype-based, multi-paradigm, dynamic scripting language that simultaneously supports object-oriented, imperative, and declarative as well as functional programming styles.

Although JavaScript is called a client side scripting language or browser scripting language, now JavaScript is used for client side i.e. server side and network programming outside of browsers, mobile and desktop app development, gaming development etc. Being.

Brief introduction to JavaScript:

Netscape engineer Brendan Eich created JavaScript in 1995, which was released in early 1997 with Netscape 2 (browser). It was named LiveScript, but as part of its marketing strategy to capitalize on the popularity of Sun Microsystems’ Java language,  Although there is no similarity between Java and JavaScript, it is called JavaScript. Microsoft launched JScript, a language that is almost identical to this programming language, after about 3 months with Internet Explorer.

Netscape, meanwhile, introduced the language to Ecma International (a European standard-setting body) – the first version of ECMAScript was released in 1997. This standard was further developed in 1999 as ECMAScript version 3 – and the language has not changed much since then.

The fourth edition is ruined, as a result of disagreements over the complexity of the language. However, the fifth edition of the new ECMAScript was released in 2009 on the basis of many parts of this fourth edition. ECMA International last released its sixth major edition on June 16, 2015,

Officially called ECMAScript 2015, and is now known as ECMAScript 6 or ES6.

What are Web Console and Scratchpad?

Web Console and Scratchpad are two of Firefox’s built-in tools used to test and run JavaScript codes, as well as a built-in Web Console Tool for Chrome browser users, but you won’t find Scratchpad in the Chrome browser. You can install the Scratch JS extension in the chrome browser if you want.

You can use Ctrl + Shift + I to easily run Web Console in firefox and chrome browser. Then the following output will appear:

Image
Image

The main problem with Web Console is that it allows you to execute single line code, on the other hand you can execute live code in one line on Scratchpad if you want. You can use Shift + F4 to run Scratchpad in firefox browser. And you can use Ctrl + Shift + I to run Scratchpad easily in chrome browser. After running Scratchpad you will see the following:

Image
Image

Where and how to run JavaScript Programs?

JavaScript can be run by typing in the HTML Page between the <script> start tag and the </script> end tag. You can run JavaScript by attaching it to many more language files including asp, .py. You can also run JavaScript by typing in any html tag. So let’s look at three methods:

Run between <script> start tag and </script> end tag:

Image

Explanation:

Here we have given the <start> tag to write javascript code on line 4, then on line 5 we have used the write method of document class of javascript “document.write ()” to display the text “Hello JavaScript” in our browser. And on the last line 6 we ended the javascript code with the </script> end tag.

Run javascript directly into the html tag:

Image

Image

Explanation:

 

If you click on the first button here, the word Hello Bangladesh in your p tag will be changed to Hello World, and if you click on the second button, you will get an alert.

Write JavaScript on any file with .js extension and run it:

You can easily run JavaScript on any file with .js extension, it is called external Javascript, again there are two types of external javascript, one is on your computer or host or you can work on CDN (content delivery network) server. . So let’s understand with an example:

 

First, type the following code into the script.js file:

Image

Now type the following code in test.html file:

Image

Explanation:

 

Notice here, we have used jquery CDN in line 12 of test.html file, and we have attached script.js file in local pc in line 13.

How to show the output of JavaScript?

JavaScript can display information in different ways:

1. Via the alert box using window.alert ()

    2. Write to HTML document using document.write ()

    3. Write to HTML element using .innerHTML

    4. Can be shown in the browser console using console.log ()

Use window.alert ()

You can use the alert box to display information

Image

Use document.write ()

 

We can show any output using document.write (). However, one thing to keep in mind is that after the HTML Element is fully loaded, using document.write () deletes all previous HTML:

Image
Image

Note: The document.write () method should only be used for testing.

Use innerHTML

 

To access the HTML Element, the getElementById () method of the document class is used in JavaScript.

 

The id attribute of HTML tags points to a specific element of HTML and can point to any HTML content through the innerHTML Property. Let’s understand with an example:

using console.log ()

 

To debug JavaScript codes, we often have to display different types of information, then we use the log () method of its console class. However, you need to activate the browser console via F12 or select “Console” from the menu. Or you can use Ctrl + Shift + I directly.

Let’s look at an example:

Image

 

Image

Leave a Reply

Your email address will not be published. Required fields are marked *