JavaScript The king of web Application Language

Introduce with JavaScript

Overview

JavaScript is called “The king of web Programming language”. It’s created by Brendan Eich in 1995. It’s not a compiled language as well as it is a interpreted language. But JavaScript run fast any other interpreted language like Python. JavaScript engine, V8, is written in C++. As JavaScript is a Scripting language it has no input output method. But using Node.js you can take input and provide output using readline method.

JavaScript is a multi-paradigm, dynamic language with types, operators, standard build-in object and method. JavaScript support OOP with object Prototypes inside a class (learn more about prototypical-inheritance and classes). Like All programming language JavaScript has some types like:

  1. Numbers
  2. String
  3. Boolean
  4. Symbol
  5. Object

6. null

7. undefined

Let’s learn about some of these type little bit……!!!

Numbers

The Number type is a double-precision 64-bit binary format IEEE 754 value (numbers between -(253 − 1) and 253 − 1). Number has many build-in function like parseInt(), parseFloat(), isNAN(), isFinite() etc. There some some special values in JavaScript like NAN, infinite, -infinite etc.

Let’s explain some of them.

parseInt()

This function has tow parameter. 1st is value and 2nd is base. 2nd parameter is optional. But you should always use it. parseInt() will parse non-string objects if they have a toString or valueOf() method.

Syntax: parseInt(‘string’, base);

Example: parseInt(‘55’, 10);

If you want to convert this number in binary format, just change base 2. Then you get binary value.

Learn more.

parseFloat()

This function is same as parseInt() function. parseFloat() is convert number in float type number. parseFloat() will parse non-string objects if they have a toString or valueOf() method.

Syntax: parseFloat(‘string’);

Example: parseFloat(‘44.4546’);

Learn more

isNAN()

This function return Boolean value. Is NAN return true. Is have a value it return false.

Example:

Number.isNAN(NAN) //true

Number.isNAN(‘hello’) //false

Number.isNAN(‘’) //false

Number.isNAN({}) //false

Number.isNAN(1) //false

Number.isNAN([]) //false

Learn more.

isFinite()

Example:

isFinite(1/0) or isFinite(infinite) //false

isFinite(-1/0) or isFinite(-infinite) //false

isFinite(NAN)//false

isFinite(1) //true

isFinite(1.456453564776968) //true

Learn more

String

Strings in JavaScript are sequences of Unicode characters. Some of build-in method are charAt(), toUpperCase(), toLowerCase(), replace(), split() etc. We can find the length of a string using length property.

Example:

const str = “World”;

str.charAt(0) //output: W

str.toUpperCase() //output: WORLD

str.toLowerCase() //output: world

“Hello, world”.replace(“World” , “Tanvin”) // output: “World, Tanvin”

Learn more

Variables

There are 3 types of variable in JavaScript. var, let, const. let and const are ES6 variable declaration type.

var

var has no restriction in declaration. You can change the value of var variable. JavaScript engine don’t show error.

Example:

var name = “Tanvin”

name = “Ahmed”

console.log(name) // output: “Ahmed”

let

let allows you to declare block-level variables. The declared variable is available from the block it is enclosed in.

Example:

function(){

let name = “Tanvin”

name = “Ahmed”

console.log(name) // “Ahmed”

}

console.log(name) // Error

const

const variable is not allow to change the value of the variable more. It’s a constant variable. Value not changeable.

example:

const name = “Tanvin”

name =”Ahmed”

console.log(name) // Error

Operators

Many operator are present in JavaScript like Arithmetic, Comparison , Assignment, Bitwise, Logical, String, Conditional (ternary), Comma, Unary, Relational .

Some important operator I explain briefly.

Arithmetic Operator

+, -, *, /, %, ++,- -, are the arithmetic operator.

Example:

1+2 = 3, 2–1 = 1, 2/1=2, 5%3=2,

x = ++2 //output 3

x=- -2 //output 1

For more please go to the link.

Conditional Statement

2 type of conditional statement are in JavaScript. if-else, switch.

if-else

Example:

const x= 5, y= 6;

if(x+y === 11){

console.log(11);

} else {

console.log(“result is not 11”);

}

output: 11

switch

Example:

const x = 1;

switch(x){

case1: console.log(“one”)

break;

default: console.log(“no match found”)

}

output: one

Learn more

Object

object is a collection of information of any thing. Suppose I am a object and my height, width, color, favorite food are the collection of data. we can easily write these with an object. 2 way to declare object. 1st const obj = new Object(); 2nd const obj = {}; . We can insert data in a object in 3 way.

1st ,

const obj = {

name: “Tanvin”,

age: 22,

Height: 5.5

}

2nd

const obj = new Object()

obj.name = “Tanvin”;

obj.age=22;

obj.height = 5.5

3rd

const obj = {}

obj[“name”] = “Tanvin”

obj[“age”] = 22

Learn more

Array

Array is a collection of data like object but not similar to Object. In Array we can iterate data by using loop and do many thing with data. Array declaration is const arr = [];

Example: const arr = [1, 2, 3,4,5];

Learn more

Functions

JavaScript is also known as a functional programming language. There are many type of function in JavaScript. Pure function, inner function, recursive function, anonymous function etc. Function have many parameter or not. A function have a return value or give output doing something. Function must invoking for execution. Without invoking or call function can not work.

Example: A simple function

function add (num1, num2){

const result = num1 + num2;

return result;

}

const addition = add(2, 4);

console.log(addition) // output: 6

In this function, we pass 2 parameter num1 and num2, and add these number in the function, and then get result in result variable and return it. Then we call this function or invoking this function passing 2 number, as parameter value and save return value in addition variable and console log it. Then we get our expected output.

Learn more

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store