Introduction of JavaScripts and its Basics

Md. Sazzadur Rahman
4 min readMay 5, 2021

Javascript was created by Brendan Eich in 1995 which was named after Java to increase its popularity on those times. After Microsoft released Jscript with internet explorer, Netscape submitted the JavaScript to a European Standards Organization named Ecma International which released its 6th standard version ES6 in 2015. Javascript is a simple and more confusing programming language that used almost all types of application as a scripting language. Like other programming languages, it has no input or output concept, it is used with a browser to provide a mechanism for communicating with the outside world.

Javascript is object-oriented programming with object prototypes that also support functional programming language which stored in a variable and passed around like any other object.

Basics of Javascript:

String.prototype.charAt()

charAt is a method of string that returns the value of a certain index in a string.

let message = “Hello world”;
const indexFour = message.charAt(4);

console.log(indexFour); // Output: “o”

String.prototype.concat():

concat is a string method that concatenates a string with the calling string and returns a new string.

let msg1 = “Hello”;
let msg2 = “there”;

const msg3 = msg1.concat(“ “, msg2);
console.log(msg3)

String.prototype.indexOf():

indexOf is a string method that returns the starting index number from the calling string for a certain word or string and if it is absent it turns -1.

const str = ‘The name of my country is Bangladesh’;
const item = ‘Bangladesh’;
const index = str.indexOf(item);
console.log(index) //26

String.prototype.slice()

slice is a string method that pieces the calling string from a certain index to the desired index and returns it as a string without unchanged the calling string.

const string = ‘The name of my country is Bangladesh’;

console.log(string.slice(26)); //output: “Bangladesh”

console.log(string.slice(4, 25)); // output: “name of my country is”

console.log(string.slice(-10)); // output: “Bangladesh”

String.prototype.split()

split is a string method that divides a string into the substring using a searching pattern and store that’s substring to an array.

const string = ‘The name of my country is Bangladesh’;

const subString = string.split(‘ ‘);
console.log(subString);
// output: Array [“The”, “name”, “of”, “my”, “country”, “is”, “Bangladesh”]

String.prototype.includes()

includes is a string method that retuns boolean “true” or “false” if one string is present into another string or a value is present in an array.

const str1 = ‘The name of my country is Bangladesh’;

const str2 = ‘Bangladesh’;

console.log(str1.includes(str2));
// output:true

String.prototype.toLowerCase()

toLowerCase() turn into the whole string in a lowercase.

const str = ‘Bnagladesh is beautiful country’;
console.log(str.toLowerCase());
// output: “bnagladesh is beautiful country”

String.prototype.toUpperCase()

toUpperCase() turn into the calling string into uppercase.

const str = ‘Bnagladesh is beautiful country’;
console.log(str.toUpperCase());
// output: “BNAGLADESH IS BEAUTIFUL COUNTRY”

String.prototype.trim()

trim is a method that removes the white space from both the start and ends of a string.

const message = ‘ Hi There… ‘;

console.log(message.trim());
//output: “Hi There…”

String.prototype.trimEnd()

trimEnd() is a method that removes the white space from the ends of a string.

const message = ‘ Hi There… ‘;

console.log(message.trim());
//output: “ Hi There…”

String.prototype.trimStart()

trimStart() is a method that removes the white space from the starts of a string.

const message = ‘ Hi There… ‘;

console.log(message.trim());
//output: “Hi There… “

Number:

Number.parseInt()

Number.parseInt() convert the float into an integer and return NaN if it is a string.

Number.parseInt(“abc”);
// output: NaN
Number.parseInt(123);
//output: 123
Number.parseInt(123.567);
//Output: 123

isNaN()

isNaN returns true if it is not a number and returns false if it is a number.

isNaN(“abc”);
//output: true
isNaN(123);
//output: false

Math

Math.abs()

Math.abs() returns an absolute value, and that is always positive.

console.log(Math.abs(3–5));
// output: 2

Math.ceil()

Math.ceil returns the subsequent largest integer.

console.log(Math.ceil(2.1));
// output: 3

console.log(Math.ceil(2.8));
// output: 3

Math.floor()

math.floor() always return the previous nearest integer as an output.

console.log(Math.floor(2.1));
// output: 2

console.log(Math.floor(2.8));
// output: 2

Math.round()

Math.round() turn the value into the nearest value as an output.

console.log(Math.round(1.4));
// output: 1
console.log(Math.round(1.5));
// output: 2

Math.random()

Math.random() returns a random number between 0 and 1 (less then 1).

Math.random();

//output: 0.38317738806175585

Array

Array.prototype.every()

every() methods return a boolean “true” or “false” for an array if all array element is true or false for a certain condition.

const array = [10, 15, 30, 25, 35, 38];
const result = array.every(item => item < 40);
console.log(result)
// output: true

Array.prototype.filter()

filter() method returns the array of value which is true for certain condition.

const numbers = [10, 20, 30, 50, 70, 90];

const array = numbers.filter(number => number > 30);

console.log(array);
// output: Array [50, 70, 90]

Array.prototype.find()

find() returns the first value of certain elements that satisfied the conditons.

const numbers = [10, 20, 30, 50, 70, 90];

const array = numbers.find(number => number > 30);

console.log(array);
// output: 50

Array.prototype.reverse()

reverse() method reverse the whole array according to their index.

const array = [1,2,3,5];
console.log(array.reverse());

// output: Array [5, 3, 2, 1]

Array.prototype.shift()

shipt() method removes the first element from an array.

const array = [10,11,15];

const newElement = array.shift();
console.log(array);
// output: Array [11, 15]

Array.prototype.unshift()

unshipt() method adds the element to an array from the first.

const array = [10,11,15];

const newElement = array.unshift(4,5);
console.log(array);
// output: Array [4, 5, 10, 11, 15]

--

--