JavaScript Functions That You Will Encounter Frequently

  1. toLowerCase(): This method allows you to convert all the characters in a string sequence into lower case.
const myName = "WREET";
console.log(myName.toLowerCase())
//expected output : "wreet"
const myNewName = "wreet";
console.log(myNewName.toUpperCase())
//expected output : "WREET"
const unTrimmed = '    How are you doing?    ';
console.log(unTrimmed.trim());
// expected output: 'How are you doing?'
const str = 'Hello everyone, Have a nice day!';
const strArr = str.split(' ');
console.log(strArr);
// expected output: '['Hello', 'everyone,', 'Have', 'a', 'day!']'
const str1 = 'Hello ';
const str2 = 'World!';
console.log(str1.concat(str2));
//expected output 'Hello World!';
const strWhole = 'My name is wreet';
console.log(strWhole.slice(3));
//expected output: 'name is wreet'
const randomStr = 'My name is wreet';
console.log(randomStr.startsWith('My'));
//expected output: 'true'
const randomStr2 = 'My name is wreet';
console.log(randomStr2.endsWith('et'));
//expected output: 'true'
  1. Math.abs(): Returns an absolute value of a number.
console.log(Math.abs(-2));
//expected output: '2'
console.log(Math.trunc(10.6));
expected output: '10'

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Wreet Sarker

Wreet Sarker

Materials and Metallurgical Engineering graduate. Machine learning and Data Science enthusiast.