JavaScript built-in methods used in String and Number

MD. Razaul Haque Subho
2 min readMay 4, 2021

--

Today we are going to skim through built-in methods which are frequently used in javascript programming. Don't miss to go through all the way as there a surprising knowledge at the end ;)

Some of the basic built-in String Method in JavaScript–

charAt()— It returns the character of the given index. Note that, All the string index starts from 0. Therefore, character = string[index-1]

Example –

var name = “shuvo”;

console.log(name.charAt(0));

returns => s.

concat ()— It basically combines any string, character, number or any sort of data having no gap.

Example –

Var a = “Appl”;

console.log(a.concat(“e”));

returns => Apple.

toLowerCase ()— It basically converts all the string/characters into the lower letters.

Var name = “HAMID”

console.log(name.toLowerCase());

returns => hamid

split ()— Basically tears apart the string with some parameters on it. Based on the parameter inside the split method, it divides the string accordingly.

String name = “MD.Razaul.Haque.Subho”

console.log(name.split(“.”));

Output =

MD

Razaul

Haque

Subho

slice –

trim()- Removes whitespace from both ends of a String. It basically is useful when you are having extra space between the string. Trim basically maintains one space between all the words inside a string.

Example –

Var command = “Hello vivs this is carry on Jeeves ”

console.log(command.trim());

returns Hello vivs this is carry on jeeves.

indexOf ()— The indexOf() method returns the position of the first occurrence of a specified value in a string. This method returns -1 if the value to search for never occurs.

Example -

Var name = “HAMID”

console.log(name.indexOf(I);

returns => 3

Some of the Basic built-in function used in JavaScript Number.

isNaN()- NaN means not-a-number. Therefore, isNaN is a Boolean function which returns true or false based on whether the input is number or not

Example-

isNaN(1)

returns false as 1 is number.

parseInt()- converts the string into Integer value.

Example

const number = “34”

console.log(number.parseInt());

returns => 34

random()- Generates random number between 0 and 1.

console.log(Math.random());

console.log(Math.random());

output = 0.8965

output = 0.4223

etc

floor() — round the decimal number into integer with largest closest integer value smaller than the given input.

console.log(Math.floor(3.75))

output — 3

ceil()- round the decimal number into integer with smallest closest integer value larger than the given input

console.log(Math.ceil(3.75))

output — 4

Completely out of the context do you know the differences between HTTP and HTTPS ?? Here's the laziest answer for you.

We already know that HTTP (Hypertext Transfer Protocol) protocol normally uses a request to the server to get the address of a particular web address and the server in return provides the address as a response. However, when it comes to a more secure website for example payment system where you might require authentication validation of input, you might observe that instead of HTTP, HTTPS (Hypertext Transfer Protocol Secure) protocol is used. So basically, HTTP uses TLS(SSL) to encrypt normal HTTP requests and responses which certainly provides security over the website.

That's all from today lazies! Till then …..

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response