Javascript’s fundamental

Md Moniruzzaman Sojol
6 min readMay 4, 2021

Hi Everyone, Sojol here.

Today we are talking about a little bit of the fundamental concepts of javascript programming languages. If you are new to Javascript this is for you.

Javascript-image

Start with Javascript String :

If we want to store and manipulate text type data on javascript then we need string type. It is a primitive data type in Javascript;

Javascript string is an object that represents a sequence of character.

Example :

var myName=”Pitar”;

Here the variable myName have a value of Pitar;

Pitar is blocked by the double quote this is one way to declare and store text data on Javascript String;

Here another two way to declare and store text data in javascript;

Example:

var myName =’Pitar’

we can also use the single quote for store text data on Javascript String

var myName =`Pirat`
Example code

To use a multiline string, you can either use the + operator or the \ operator we use the ES6’s template literal or Backticks.

For example:

Here I am showing to console The Backticks type which is message2

Example code of multiline String

Now we want to manipulate a string with some build-in Method of Javascript String:

There are many methods to control a string :

charAt(i) — returns the character at the specified indexconcat()- to join to or more stringreplace()-replaces a string to another stringsplit()-convert to string to an array of stringsubstr(start,end)-return a part of stringslice(start,end)-return a part of stringetc.

Now we will see some of the code of the Javascript String Method in the editor:

Example code

Today that’s end of the string discussions.For more you can go here

Now our topic is Javascript Number:

In this section, you will learn about JavaScript Number with the help of examples.JavaScript is a primitive data type. For Example :

const a = 3; const b = 3.13;

Unlike in some other programming languages, you don’t have to specifically declare for integer or floating values using int, float, etc. just simply you can declare as a variable and set value with a number. For Example :

Declare a number

In JavaScript, NaN(Not a Number) is a keyword that indicates that the value is not a number. Performing arithmetic operations (except + ) to numeric value with string results in NaN. For example:

Not A Number Example

JavaScript Number Methods: There are many number method to manipulate number type in javascript.in below editor we will see some of this:

Example of Number Methods

Here I talked about some basic mathematical operation with Number :

Some Mathematical Operation

You can learn more about Number.Go here

Now we will see a little bit about Javascript MATH Object :

JavaScript Math object provides several constants and methods to perform the mathematical operations. Math object doesn’t have any constructor. For Example:

example of Math object

Now we will see some of the Math objects in Javascript :

abs()- It returns the absolute value of the given number.acos() -It returns the arccosine of the given number in radians.asin()- It returns the arcsine of the given number in radians.atan() -It returns the arc-tangent of the given number in radians.cbrt()- It returns the cube root of the given number.ceil() -It returns a smallest integer value, greater than or equal to the given number.cos() -It returns the cosine of the given number.cosh() -It returns the hyperbolic cosine of the given number.exp()- It returns the exponential form of the given number.floor()- It returns largest integer value, lower than or equal to the given number.hypot()- It returns square root of sum of the squares of given numbers.log() -It returns natural logarithm of a number.max()- It returns maximum value of the given numbers.min()- It returns minimum value of the given numbers.pow() -It returns value of base to the power of exponent.random() It returns random number between 0 (inclusive) and 1 (exclusive).round()- It returns closest integer value of the given number.sign()- It returns the sign of the given numbersin()-It returns the sine of the given number.sinh()- It returns the hyperbolic sine of the given number.sqrt()- It returns the square root of the given numbertan()- It returns the tangent of the given number.tanh()- It returns the hyperbolic tangent of the given number.trunc()- It returns an integer part of the given number.

Some important properties of Math Object:

Math.PI // returns PIMath.E // returns Euler’s numberMath.LOG2E // returns base 2 logarithm of EMath.LOG10E // returns base 10 logarithm of EMath.SQRT2 // returns the square root of 2Math.SQRT1_2 // returns the square root of 1/2Math.LN2 // returns the natural logarithm of 2Math.LN10 // returns the natural logarithm of 10

Some example of Math Objects:

Example of Math Object

If you are interested to learn more about Js Math objects then you may go here.

Now our topic is Javascript Array:

Array is a common data structure in Javascript. We can store all types of data in one variable called Array.In this section we are going to know about one dimensional array in javascript.

Example:

var array=[32,4,'pitar'] 

We can access the value throw index. If we want to access values from this array look the following code :

console.log(array[0]);//return 32 
console.log(array[1]);//return 4
console.log(array[3]);//return pitar
or if we can access all array in one time
the we can use the javascript loop
Example:for (var i = 0; i <= array.length; i++) {console.log(array[i]);}

Now we know the basic array. Now it’s time to know about some interesting methods of Array in Javascript.

push()   aads a new element to the end of an array and returns the new length of an arrayunshift()    adds a new element to the beginning of an array and returns the new length of an arraypop()    removes the last element of an array and returns the removed elementshift()  removes the first element of an array and returns the removed elementsort()   sorts the elements alphabetically in strings and in ascending orderslice()  selects the part of an array and returns the new arraysplice() removes or replaces existing elements and/or adds new elementsconcat()   joins two or more arrays and returns a resultindexOf()    searches an element of an array and returns its positionfind()   returns the first value of an array element that passes a testfindIndex()  returns the first index of an array element that passes a testforEach()    calls a function for each elementincludes()   checks if an array contains a specified element

Here some example code of array methods:

some array methods

This is from my side for today. thanks, everyone for reading the content.If any query, please comment below..

HAPPY CODING!!!

--

--