The most important JavaScript topics every web developer should know
JavaScript is one of the most popular and widely used programming languages in the world right now.
Function
Functions are one of the fundamental building blocks in javascript.
Why functions?
You can reuse code define the code once and used it many times.
Function declaration:
function added(a, b){
console.log(a + b);
}
added(10, 20); //30
Strings
JavaScript string stores a series of characters like “John Smith”. JavaScript strings are used for storing and manipulating text.
var string = “Hi I am a Simple String”;
IndexOf()
The indexOf() method return the position the first occurrence of specified value of a string.
const a = [“kamal”, “jamal”, “salam”, “arman”];
const b = a.indexOf(“salam”);
console.log(b); // 2
Here Salam name index number is 2
const a = [“kamal”, “jamal”, “salam”, “arman”];
const b = a.indexOf(“akash”);
console.log(b); // -1
Because indexOf() -1 has given the number as the name cannot be found
Slice()
The slice() method extracts parts of a string and returns the extracted parts in a new string.
const numbers = [1, 2, 3, 4, 5];
const numbers2 = numbers.slice(1, 4);
console.log(numbers2); // [2, 3, 4]
Number
The Number function converts the object to a number that represents the object’s value.
const a = “100”;
const num = Number(a);
console.log(num); // 100
Filter()
The filter() method creates an array filled with all array elements that pass a test provided as a function.
const number = [1, -1, 2, 3, 4];
const numbers2 = number.filter(function(value){
return value >= 0;
});
console.log(numbers2); // [1, 2, 3, 4]
Map()
Map is a JavaScript array method. The map() method creates a new array with the results of calling a function for every array element.Map method does not change the array.
const numbers = [1, 2, 3, 4, 5];
const numberDouble = numbers.map(double);
function double(value, index, array){
return value * 2;
}
console.log(numberDouble); // [2, 4, 6 , 8, 10]
Shift
The shift() method removes the first item of an array.
const array = [1, 2, 3, 4, 5];
array.shift();
console.log(array); // [2, 3, 4, 5]
Shift has deleted the first element.
ParseInt()
The parseInt() function parses a string and return a integer.