10 things I never know before today about JavaScript

Mehedi hasan
3 min readNov 2, 2020

1.charAt: charAt is a JavaScript string method which using to access value that’s representes the current index inside the chartAt method.

const name = ‘mehedi hasan’;const whichValue = name.charAt(4); // it’s represent dconsole.log(whichValue); //output: d

2.indexOf: Generally indexOf used to search the element which existed or not in a string. That’s syntax is- str.indexOf(searchValue [, fromIndex]). But when search value was an empty string then return index number which exists on second parametres.

const js = ‘I am a javascript lover’;console.log(js.indexOf(‘am’)); //expected output 2console.log(js.indexOf(‘ ‘, 4)); //expected output 4

3.trim,trimStart,trimEnd: trim method used to remove white space from both ends of a string. trimStart is used to remove whitespace from beginning whether trimEnd used to end.

const welcome = ‘ Welcome medium.com ‘;console.log(welcome.trim()); //expected output ‘welcome medium.com’console.log(welcome.trimStart());// expected output ‘welcome medium.com ‘console.log(welcome.trimEnd());// expected output ‘ welcome medium.com’

4.trunc: trunc is a JavaScript method which returns integer part of any decimal number.

var truncNumber = 45.89;console.log(Math.trunc(truncNumber));// expected output 45

5.some: some is JavaScript array method which checks if any of elements in an array pass a test. When any elements pass test then it’s returns a boolean value.

const ages = [10, 15, 18, 20];const adult = ages.some(checkAdult);function checkAdult(age) {return age >= 18;}console.log(adult); // expected output true

6.every: every is a JavaScript array method which checks every elements in an array pass test and when every elements pass test then return true whether it’s returns false.

const ages = [10, 15, 18, 20];const adult = ages.every(checkAdult);function checkAdult(age) {return age >= 18;}console.log(adult); // expected output false

7.fill: JavaScript array method fill changes all elements of an array to a static value following syntax. It’s has three parametres first value indicate which value we want to filled, second value indicates starting index and third value indicates ending values until value filled.

syntax: array.fill(value, starting index, until we want change)

const fillNumber = [1, 2, 3, 4];console.log(fillNumber.fill(4, 1, 3)); // expected output

8.forEach: forEach method returns ones elements in an array. We can call a callback function inside forEach method. Every callback function returns three value which is current element, index, array.

const num = [5, 10, 15, 20];num.forEach( elem => console.log(elem));

9.reduce: reduce function used when we want something to do with all elements of an array. reduce method has two arguments ones callback function other initial value. callback function has two parametres ones accumulator other current value. after arithmetic expression value store on accumulator.

const number = [1, -1, 2, 3];const sum = number.reduce((acc, curr) => {return acc + curr}, 0);console.log(sum)// expected output 5

10.SSL( Secure Sockets Layer): when we browsing internet i saw some url has extra ‘s’ which means that url has secured and encrypted. Users private information like bankdetails, banktrasaction are secured through this ssl certificates though any kinds of hacker couldn’t attack.

--

--