Fundamentals of JavaScript
(1) charAt():
This is a string objects method that returns a new string
syntax — let character = str.charAt(index)
Example:
const sentence = ‘My name is Mowmita Ahmed.’;
const index = 4;
console.log(`${sentence.charAt(index)}`);
(2) concat()
This is a string method that returns a new string of concatenated string arguments of the calling string.
Example:
const str1 = ‘Mowmita’;
const str2 = ‘Ahmed’;
console.log(str1.concat(‘ ‘, str2));
// expected output: “Mowmita Ahmed”
(3) slice()
It’s a string method which returns a new string after extracting it without modifying the original sentence.
Syntax — str.slice(beginIndex[, endIndex])
Example:
const str = ‘My name is Mowmita Ahmed Chowdhury.’;
console.log(str.slice(21));
(4) endsWith()
It’s a string method that determines whether a string ends with the character of specified string .It returns true or false.
Syntax- str.endsWith(searchString[, length])
Example:
const str1 = ‘Girls are the best!’;
console.log(str1.endsWith(‘best’, 17));
(5) isNaN()
It’s a string method that determines whether the value is number or not.
Syntax- Number.isNaN(value)
Example: Number.isNaN(y)
(6) Math.ceil()
This is a function which returns the next largest number.
Syntax- Math.ceil(x)
Example: console.log(Math.ceil(2.83));
(7) Math.floor()
This is a math function which returns the largest integer less than or equal to a given number.
Syntax — Math.floor(x)
Example: console.log(Math.floor(-1.09));
(8) Math.min()
This is a math function which returns the lowest valued number.
Syntax- Math.min([value1[, value2[, …]]])
Example:
console.log(Math.min(24, 31, 18));
(9) filter()
This function create a new array with all elements which pass the conditions of the function
Syntax- let newArray = arr.filter(callback(currentValue[, index, [array]]) {
// return element for newArray, if true
}[, thisArg]);
Example:
const words = [‘momo’, ‘mowmita’, ‘tamim’, ‘momi’, ‘Tanha’];
const result = words.filter(word => word.length > 4);
(10) find()
This method returns the value of the first element which pass the test condition of the function.
Syntax- arr.find(callback(element[, index[, array]])[, thisArg])
Example:
const tama2 = [7, 17, 28, 15, 55];
const fing= tama2.find(element => element > 12);