10 important operations you should know in Javascript.

Musiur Alam Opu
8 min readMay 5, 2021

JavaScript is a high-level language. It has many advantages with the most important and useful operations and functions. I’m gonna write about 10 of them.

1) For loop in Javascript, you must know.

As a programmer, we have to iterate many things most of the time in coding. To implement the iteration we have a programming concept of iterating through a loop. Now, we are gonna discuss ‘for loop’ in Javascript.

Javascript is a high-level programming language. The syntax of for loop in javascript is similar to C++, Java, C, and many other popular languages.

The basic syntax of for loop in javascript is:

picture 1

or,

picture2

A for loop has mainly two sections in its signature, A parathesis with three statements, and a block of Curli braces for codes. In the parathesis, In pictures 1 and 2 we can see that every statement separated by a single semi-colon.

In the first part or statement, we have to define a variable using var or let but, never use const. Again here we have to assign the declared variable which must be an integer value.

In the second part, we have defined that how many times a loop will be iterated by increasing or decreasing the value of i. To assign the iteration value we can simply write an integer value or, assign a variable that contains an integer value. The last part can be incremented++ or, decremented - -. These two symbols mean increment by one or decrement by one.

When our program will start, for the first time the value of I will be 0 or whatever we assign. in the second part, this will check the condition whether the program will iterate the operation in the code block of the loop or not. In the third part, the value of i will be incremented or decremented.

After increment or decrement, the program will try to compare the value of i with the end value in the second part of the parenthesis again. If the condition is true, then the iteration will be continued else the program stop or break the iteration.

So this is how a for loop works in javascript. I hope you understood.

2) How to get a substring of a string in Javascript?

We can get a substring from a string in Javascript easily using a little function.

The slice function. Mainly the slice function takes two parameters which are starting index and ending index of the desired substring. Here in this picture, we can see we have a string variable which is country. In this variable, we have the string “Bangladesh is a densely populated country.” We want to cut a piece of text from this string using the slice function. We call the slice function as a property of the country variable and enter 4, 10 as starting and ending index of the desired substring in the parenthesis. As a result, we got ‘ladesh’ in the terminal. So this is how we can get a substring from a string in Javascript using the slice function.

3) How to implement while loop in Javascript?

Iteration is a kind of part and parcel of the coding life of a programmer. There are many iterators in Javascript like for loop, for each loop, while loop, do-while loop, etc. Today we are gonna know how works while loop in Javascript.

In this piece of code, we can see the basic syntax of while-loop in Javascript. While loop has a parenthesis and a block for codes inside the Curli braces. In the parenthesis, we have to write the condition that how many times the loop will iterate. We can see that in the above picture, we are comparing two values i and end that are declared in-line numbers 1 and 2.

At the first time, the while loop has the initial value in i and which will be compared or increased and decreased with the boundary value. After executing the first time the value of i will be increased by one (++) or decrease by one (- -). At the second time, the value of i will be compared with the value in the end variable or 10. If the condition is true, then the code in the while loop block will be executed again, else the condition is false, then the program breaks the loop.

I hope you guys understood the process.

4) How to implement Push operation the concept of Stack in Javascript?

In data structure pushing an element in a stack is a comment operation. Today we are gonna see that how can we implement this in Javascript.

First of all, we have to create an array of integer numbers. For this numbers is the array. It has four elements 1, 3, 4, 5. We know that in the stack, push operation adds a value in an array at the end. If we try to push 100 in the array then it will be added right after the last element which is 5. That means we can add an element at the top of the stack in this way.

5) How does map function work in Javascript?

“map” function is very useful when we want to iterate the values without any loops. The map is not a loop but works like a loop. If we use this function on an array, then it will return us a new array updating the values of each element as we want. In the above picture, we can see that numbers are an array of five integers. squareOfNumbers is a variable where we are storing the mapping array of numbers. We are square each element in the numbers array using map easily.

6) How to convert any type of data to string type data?

Sometimes we may need to convert any type of data to string type data. To do that we have a function named toString() function. By using this we can easily make any kind of data to string type data. let’s see an example where we are going to convert int to string, floating to string, character to string, boolean to string.

At first, we have taken an integer type of variable named number which contains 10000. We are gonna convert it into a string using this statement in line number 3. As a result, after printing the type of converted value, we got the string type in the terminal. In the same way, we can convert all the types of variables into strings.

7) Uses of toUpperCase and toLowerCase in Javascript.

There may be many occasions when we will have to convert a string into a complete uppercase string or lowercase string. To do that we have toUpperCase and toLowerCase functions. Let’s see in the code.

8) Splitting any string into multiple strings using split() in Javascript.

We can easily split any string into multiple strings using the split function in Javascript.

To do what we are gonna do is, declare a string variable assigning with a string. Then call the split() function as a property of that declared variable which is nameString in the above code. In the parenthesis of the split function, we have to enter a string part of this nameString variable to specify the splitting point in the string. Here we are using a space. That means we will get three strings separated by spaces.

9) Some mathematical operations from the math library in Javascript.

As a programmer, we have to do many mathematical operations. Among them, we are gonna see some important operations. Using max, min, and random function in Javascript.

Here in the above code, we can see that we have two variables names number1 and number2. From line number 4 to 8 we are printing some values in a string format. To use the math library functions we have to just type Math and then have to use a dot and right after that, we have to use the function name. For the max and min functions, we have to pass two parameters in the parenthesis. These parameters are number1 and number2. As a result, we will get the max and min between the number1 and number2. For the random function, we have to just type Math.random(), and that will give us a floating random number.

10) Not an operation but need to know.

What is SSL? S for Secure, S for the Socket, and L for Layer. Basically, we developers make websites and host them on the internet. In most cases, we face HTTP and HTTPS. The extra S means this website is to secure using SSL. An SSL is security technology. It’s a protocol for servers and web browsers. SSL makes sure that data passed between the two are private. This is done using an encrypted link. That encrypted link connects the server and browser. Therefore, it’s very hard to hack the site for any hacker.

To recapitulate the whole, these most important things we should know in Javascript to have a better command of Javascript. Thank you very much for reading this.

--

--