JavaScript Basic

JavaScript is a dynamic high-level scripting programming language. It is mostly used in web development however can be used for android, IOS and windows app development. Brendan Eich on December 4 1995 developed JavaScript. It is an event-driven functional programming language and is prototype-based. It itself is synchronous in nature however uses different web APIs and other techniques to achieve asynchronous programming. Its Documentation is maintained by Mozilla Corporations at Docs.

Basic Features Of Javascript:

Dynamic: JavaScript is dynamic as the variable doesn’t need any explicit type before use.


let variable = 1;

let Tesla =”sir”;

the variable is of type number and Tesla is of type string without explicit reference and is based on usage.

Weakly typed: 

JavaScript is weakly typed that is certain data types can be implicitly coerced to another data type.


let variable=1;

let another =”sir”;


This results “1sar” as 1 is implicitly converted to string through the use of the + operator.

Object-based Programming language:

JavaScript is a prototype-based object-oriented programming language that is JavaScript uses prototypes for inheritance. It has a class keyword but does the inheritance through prototyping under the hood.


let person =


name =”Adam”


This returns an object person which has different methods based on the Object prototype.

Just-In-Time Compilation:

JavaScript uses Just in Time for the compilation of the code. Chrome uses V8, Firefox uses SpiderMonkey engine, and Safari uses JavaScriptCore as the compiler which all have the feature of Just in Time which compiles at the time of compilation rather than ahead of time like C which makes optimization easier.

Let’s create a JavaScript app which will print “Hello World”:
We will run the app on the browser. So, let’s create an index.html. This is done by creating a file with a .html or .htm extension using any text editor. We will use Visual studio code:

Lets JavaScript by providing the source of the script using the <script> tag. JavaScript can extension of .js.

Let’s create a bare HTML page with a script tag which source js file.

Using java script in HTML file shows the process of adding script in HTML

The write the code for creating a hello world application as :

Shows process of printing hello world a basic JavaScript app

console.log(“Hello World);

The file can be run using live server extension on vs code and pressing right-click on the HTML page and clicking open on live server. Or you can click the file on file manager and click on open with chrome or any other browser.

Let’s create a function on JavaScript that returns a sum of two numbers:

Function in JavaScript starts with the function keyword. The syntax of the function is as:

function Name(argument1, argument2){

//block of code


An example is :

function sum(a, b) {

return a + b;


shows function which add two numbers in Javascript

console.log(sum(1, 2));

Result of sum function which shows 3 and is result of function

Javascript Array:

Let’s create an Array in JavaScript:

The array is a single variable that stores different values at once. In JavaScript, it is a type of object so it inherits from the Object prototype.

The array can be created by the following methods:

const arr = [1, 2,3];

const arr = new Array(‘a’, ‘b’, ‘c’);

Both methods create an Array so any method can be used to create an Array.

To learn more about JavaScript Array:

Creating Array methods shows two method of it which is basic in javascript
Result of Array creation and shows result of two methods.

Basic Of Objects In Javascript:

The object is an entity that has properties and types. It is a variable that stores multiple key-value pairs and the value can be functions, variables and such. Everything except primitive values is an object and inherit from object prototypes. The object is denoted using Object literal which is {} that is pair of curly braces.

Let’s create an Object using a different method:

that is

const obj ={
key1: “value”


const obj2= new Object();

obj2.key2 = “ value2”;



Both methods create a new Object. So many methods can be used.

Ways to create Objects and to iniitialize the object in Javascript.
Result of creation of function of two methods.

To Learn more about JavaScript and its asynchronous feature : Asynchronous JavaScript

One thought on “JavaScript Basic

Leave a Reply

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