Notes on Javascript

Jashim Uddin
2 min readMay 5, 2021

1. pharseInt()

Convert an string that contains number , We can opt-in easily withbuilt-in function parseInt() function in javascript which takes bases for the conversion as an second argument which we should always provide:

example:

parseInt(‘44’, 10); // 44

parseInt(‘034’, 10); // 34

2. parseFloat() this funct parses an argument and returns a floating point number. If a number cannot be parsed from the argument, it returns NaN.

Syntax: Number.parseFloat(string)

it takes string as an argument and converts to float number, if it fails then returns NaN.

3. toFixed() — sometimes we have calculations on several sales point, within this point we need decimal point, so we can emerge it by using toFixed() function

syntax: toFixed(digits)

number of digits to appear after the decimal point; this may be a value between 0 and 20. if no argument is given, it treated as 0.

string manipulation:

4. includes(searchString, position) here position is optional and takes 0 if omitted.

Returns true for searchString, otherwise returns false.

‘hello, jim’.includes(‘jim’); // true ( it is case-sensitive )

5. substr() returns a portion of the given string, starts with given index and extends for the given number of characters.

Example:

const gender = ‘female’;

console.log(gender.substr(2,4) // male

6. toLowerCase() this method returns the value of the string converted to lower case. It doesn’t affect the original string itself.

const gender = ‘FEMALE’;

console.log(gender.toLowerCase()); // female

7. ToUpperCase() this method is reverse of toLowerCase() method, it converts given string to Upper case.

8. Slice() method extracts a part of a string and returns a new string without modifying original string.

Syntax: slice(startIndex, endIndex)

it is zero based index, if negative value is given, then it starts str.length — negative index

Example:

const str = ‘welcome’

console.log(str.slice(3,7); // ‘come’

9. push()

this method adds one or more elements to the end of an array and returns new length of the array.

Example :

const fruits = [‘apple’, ‘banana’]
fruits.push(‘papaya’, ‘orange’]

console.log(fruits.lenght); // 4

10. pop()

remove the last element from an array and returns that element which is been removed.

Example:

let fruits = [‘apple’, ‘banana’, ‘papaya’, ‘orange’];

console.log(fruits.pop()); // orange

console.log(fruits); // [‘apple’, ‘banana’, ‘papaya’];

11. reverse() — this method reverse the given array.

const array1 = [‘one’, ‘two’, ‘three’];

console.log(‘array1:’, array1);

--

--