Let’s Start a Journey With JavaScript
By: Sadman Sakib Jisan
Tags: JavaScript, Javascript Tips

At the very first age, JavaScript was called LiveScript. An engineer named Brendan Eich has created JavaScript in 1995. There was a little confusion about the name with Java and JavaScript. After several months Microsoft released JScript with Internet Explorer 3. After that Netscape submitted JavaScript to Ecma International. In 1999 ECMAScript edition 3 launched and it has stayed pretty much stable ever since.

An Overview of JavaScript:

JavaScript is a dynamic language with many type, operators, objects, and methods. JavaScripts’ syntax is inspired by Java And C language. A programmer can work with object prototypes, instead of classes and that’s why JavaScript supports OOP. And Lastly JavaScript also supports functional programming. JavaScripts’ type diagram looks more like this:

Number String Boolean Object Symbol Undefined Null.

Variable:

In JavaScript, we can declare a variable by using these three keywords.

let var const

When you using the ‘’let’’ keyword it allows you to declare block-level variables. And the value of this variable can be changed.

“const” allows you to declare variables you cant change. The variable is available from the block it is declared in.

And now the most commonly used variable is “var”. This variable has no restrictions like the other two. This variable is available from the function where it is declared in.

Operators:

“+, -, *, /” this is are JavaScripts’ numerical operators. We use ‘’=’’ this for assigning values. In srting and number if we need to compare between something we can use “<, >, <=, >=”. Last but not least “!= !==” this is are also some operators in JavaScript.

Control Structures:

If you have any idea about the control structures of C language, then you will already know about the control structures of JavaScript also. Because there are some similarities between C and JavaScript.

“if-else” conditionals can be used in JavaScript. You want to print a age message and you set if age is less than 10, print a message “child” message, if not, but age is less than 20, print a “adult” message, otherwise a “old”:

if(age<10){

console.log(“child”);

}

else if (age<20){

console.log(“adult”);

}

else{

console.log(“old”);

}

JavaScript has “while-do while” loop. When you want a basic looping then use the first one, otherwise use the second one.

while (i <= j) {

console.log(i);

i += 1;

}

this code will run the loop over and over again. when the value of i=10 then it will stop.

In JavaScript, you can use the “for” loop also. and again this for loop are similar to C language.

for (var i = 0; i < 5; i++)

{

console.log(i);

}

console.log(sum);

JavaScript has Switch and Break statement.

Array:

In JavaScript array is a special and magical term. Special because its a special type of object and magical, because array works with magical terms, call length.

var a = new Array();

a [0] = ‘product1’;

a [1] = ‘product2’;

a [2] = ‘product3’;

when you use length property it will show how many objects inside an array. In a convenient way:

var a = [‘product1’ , ‘product2’, ‘product3’];

a.length; // 3

Objects:

In JavaScript, objects are king. If you understand objects, you understand JavaScript.

Almost everything in JavaScript is an Object without primitives values.

var playerDetails= {

firstName:”Cristiano”,

lastName:”Ronaldo”,

position: “Forward”,

currentTeam: “ Juventus”,

jerssyNumber: 7,

matchFit: true

};

In playerDetails variable every details are objects. String, Boolean, Number every thing is object.

String:

When you want to store data in text form, then use “String”. Like array we can use the length property to find the length of a string. String literals can be specified using single or double-quotes.

Some Useful method is String:

‘charAt’ method is used to access an individual character in a string.

“concat” method is used to combine the text between two string.

“indexOf” method is used to return the index within the string.

“endsWith” method is used to find where the string ends.

“slice” method is used to Extracts a section of a string and returns a new string.

“toUppercase” method is used to Returns the calling string value converted to uppercase.

Number:

JavaScript numbers can be written with or without decimals. In other programming languages, there are different types of numbers, like integers, short, long, floating-point, etc. But JavaScript does not define different types of numbers. Following the international IEEE 754 standard, JavaScript numbers are always stored as double-precision floating-point numbers. JavaScript number are always 64-bit floating-point.

Some Static method of JavaScript Number

“isNaN” means is Not a Number. Determine whether the passed value is NaN.

The “parseFloat” function parses a string and returns a floating-point number. and “parseInt” function parses a string and returns an interger point number.

Math:

“math” object allows you to perform mathematical tasks. It works with a number, not with BigInt.

It’s not a constructor. All properties and methods are static in a math object.

Some important methods are,

math.floor is returning the largest integer less than or equal number.

math.ceil is returning the largest integer greater than or equal number.

math.random is the returning random number.

math.round is the returning the nearest number of an integer.

math.sqrt is the returning square root of a number.

math.min is the returning smallest number of zero and math.max is the returning biggest number of zero.

Function:

Function is a core concept of JavaScript. If anyone can understand the concept of JavaScript then he/she can understand JavaScript easily. A JavaScript function is a block of code designed to perform a particular task.

function name(parameter1, parameter2, parameter3) {

// code to be executed

}

with function keyword JavaScript defined. there can be one or two or more parameters to execute it. inside the curly bracket, the code will execute.

function name(parameter1, parameter2, parameter3) {

return ;

}

and when the code reaches the return keyword then the code will stop the execution.

But why we use Function??? Simple when we need to use a code multiple times, we just use the function, and when we need it we just call it.

[N: B] While writing this blog I take help from https://developer.mozilla.org/ and https://www.w3schools.com/