JavaScript- The king of Web
At first, the one thing that is on your mind why the king word I use??? Surely it’s a question that arises in your mind. I say king because when JavaScript was created in 1995 by Brendan Eich, another’s developer said it was a very slow language and never been used for industrial work purposes. It is a tortoise language because it was slow by that time. But the creator of JavaScript believes that his created language will be industry-based one day. After his hard work, this time JavaScript is one of the most popular languages for web developers in the last 10 years. Now a days the giants like Facebook, Youtube uses JavaScript and its popular framework.
Javascript is popular because based on its core concept developers also created some popular frameworks like ReactJs, VueJs. Surprisingly it’s also used in Backend that’s why it’s popular now.
Every language has some common concepts which is important all the time when we use it. The most usable term in JavaScript is String, Number, Array. I will discuss some of these terms attribute below.
At first, I say about String. What is String? It’s an object which is used to represent and manipulate a sequence of characters. Some popular String methods are charAt, concat, includes, endsWith, indexOf, lastIndexOf, replace, slice, split, startsWith, substr, toLowercase, toUppercase, trim, trimStart, trimEnd.
I will discuss the first four methods.
charAt(): The charAt() method returns a new string consisting of the single UTF-16 code unit located at the specified offset into the string.
Syntax: chartAt(index). This method returns an empty string.
concat(): concat means to add two or more strings in JavaScript terms. Suppose I have two strings, one is My and another is World. If I try to contact() them in a new variable then I write var output= My.concat(World). Remind it, when you try to execute output then must put My in a variable and World in another variable then concat it.
includes(): This method checks a specific word or number is available on a string or not. Suppose I have a variable named hello. In hello variables I have some string-like, var hello= “I am the king in my kingdom”. If I try to find king from the hello variable then I use the includes() method. The way is var s= hello.includes(“king”). If the king string is not in hello variable then it returns false otherwise it returns true.
endsWith(): This is similar like includes(). includes searching the string is available in the variable or not. Where endsWith() search the last string of a variable, if it’s true it returns true value otherwise return a false value.
JavaScript Numbers are also important to work on it. Some popular functions for JavaScript Numbers are isNaN, parseFloat, parseInt, Abs, ceil, floor, min, max, random, round, sqrt.
I will discuss isNan, Abs, floor in this article.
isNan(): The isNaN() function defines the value we provide is number or not. isNaN means is Not a Number.
isNaN(‘Hello’) = true, isNaN(123) = false
In the first example, the “hello” string is a collection of a word, so it’s not a number. That’s why it’s true. In the second example, the “123” is a collection of numbers, that’s why the value is false.
abs(): The abs() method returns the absolute value of a number.
Syntax: Math.abs(x)
Absolute means positive value. Suppose I have a value which is -5.25. If I want to make it positive then I use the abs() function.
floor(): The floor() method rounds a number DOWNWARDS to the nearest integer, and returns the result.
Syntax: Math.floor(x)
Suppose I have a value that is 3.4. If I want to make the float number into an integer then I use the floor function. Here I catch 3.4, if I use the floor function here, then it returns 3.
Now it turns to go to into Array. Array is one of the popular and widely used methods in JavaScript. Some different array methods are concat, every, filter, find, findIndex, forEach, indexOf, join, map, lastaIndexOf, pop, push, reduce, reverse, shift, slice, sort, splice, unshift.
I will discuss forEach, Map, Filter method here.
forEach(): The forEach() method calls a function once for each element in an array, in order. If I need this type of work like I have an array and I need to go to every element of an array for a specific result then I use the forEach() method. It has no return value.
Map(): If I need a value after executing an array then I must use the Map() method. If I use the Map() method in multiple lines then I must use the return term If I want a value for return.
filter(): If I need any logical value from an array then I use the filter method. Suppose I have an array, var ages = [32,22,55,44,10]. Now I need the values which are greater than 20, that’s the time I use the filter() method. And it will execute like this, ages.filter(age => age > 20); , the expected output is = 22,32,44,55. So, use the filter method I find out what I need.
That’s for today. Surely I will come with you another interesting method and functions of JavaScript. Stay with me. Good Bye!!!