10 JavaScript basic thing that a beginner should know

Samiul Sany
5 min readMay 5, 2021

A beginner should know this String basic things or Push, Pop before enter the intermediate Java Script

String. prototype. includes()

It performs a search that finds if a string maybe found in another string or not. If the string is found in another string if returns true otherwise it returns false and of course the includes() method is a case sensitive method. It has two syntax type. 1. includes(search string) 2. includes(search string, position).The position of the search string starts with default value which is 0.

Example : 
const sentence = 'I am a Programmer.';
const word = 'am';console.log(`The word "${word}" ${sentence .includes(word) ? 'is' : 'is not'} found in the sentence`);Output: "The word "am" is found in the sentence"

Here is another example of case sensitivity :

'Samiul Sany'.includes('SAmiul')
It returns false because of case sensitive issue

String. prototype. ends With()

The ends With() method performs and see if a string ends with characters of those exact string. It returns true if the characters is found to the end or it returns false if the character is not found.

Example :

const Sentence1= 'I am a Programmer. I lead an awesome life.';console.log(Sentence1.endsWith('lead', 25));
It returns true because at the end of 25 number position lead s there.
const Sentence2 = 'Try hard or you will be a loser or winner';console.log(Sentence2.endsWith('?'));
It returns false because there is no word like ? is found in this sentence

String. prototype. Slice()

The slice() method is used to return a new string but without modifying the original string. It has two type of index. 1. Beginning index 2.End index . Beginning index means in which which position it starts extraction .If there is no end index it extract front beginning index and go till the last index. if the beginning index is a negative number like -7 or no number/empty it process this like this str. length -3 and 0 respectively.

Example :

const str = 'If you know how program works life will be much easier than';console.log(str. slice(31));
It returns 'life will be much easier than. Because here we mention in which position it starts extraction. If there is no end index it extract till the last position of the sentence.
console.log(str. slice(7, 15));
It returns 'know how' because it start extraction from beginning index 7 and stop at 15 index

String. prototype. toLowerCase()

toLowerCase() returns the Whole string value but in lower case. The syntax is toLowerCase(). No matter what if the calling string contains uppercase or lowercase letter. If we use toLowerCase() it converts the entire string character into lower case

Example:

const sentence = 'TRy HARd AnD achieve YOUR GoAl';console.log(sentence. toLowerCase());
It returns "try hard and achieve your goal"
if convert the whole string into lower case no matter if there is a uppercase on those sentences

String. prototype. trim()

The method trim() remove all white space from both start and end. White space means space , tab , no break space. But if there is no white space in the entire string it returns the original string then.

Example:

const sentence= '   Let's chug the whole world  ';console.log(sentence);
Normal way its returns this " Let's chug the whole world ";
console.log(greeting. trim());
By using trim() method it returns "Let's chug the whole world";
no white space in this sentence

String. prototype. toUpperCase()

toUpperCase() returns the Whole string value but in upper case. The syntax is toUpperCase(). No matter what if the calling string contains uppercase or lowercase letter. If we use toUpperCase() it converts the entire string character into Upper case.

Example:

const sentence = 'there is always a way to be a successful person';console.log(sentence. toLowerCase());
It returns "THERE IS ALWAYS A WAY TO BE A SUCCESSFUL PERSON"
if convert the whole string into upper case no matter if there is a lowercase on those sentences.

String. prototype. trimStart()

The method trimStart() remove all white space from start. It just remove the white space from the beginning. White space means space , tab , no break space. But if there is no white space in the entire string it returns the original string then.

Example:

const sentence= '   I am the man with the sand    ';console.log(sentence);
Normal way its returns this " I am the man with the sand ";
console.log(greeting. trimStart());
By using trim() method it returns "I am the man with the sand ";
no white space at beginning

String. prototype. trimEnd()

The method trimEnd() remove all white space from end. It just remove the white space from the end. White space means space , tab , no break space. But if there is no white space in the entire string it returns the original string then.

Example:

const sentence= '   Your king is return from the desert   ';console.log(sentence);
Normal way its returns this " Your king is return from the desert ";
console.log(greeting. trimStart());
By using trim() method it returns " Your king is return from the desert";
no white space at end

Array.prototype.pop()

In an array if we use this method it removes only the last element of the whole array.After remove the last elements it returns the rest array. It returns undefines if the array is empty and this method is only works in an array.

Example:

const names= ['samiul', 'sany', 'nobody', 'everybody', 'someone' , 'somebody'];console.log(names. pop());
It removes the last element 'somebody' and return the rest element
['samiul', 'sany', 'nobody', 'everybody', 'someone']

Array.prototype.push()

In an array if we use push() method it adds one or more elements at the end of the array and returns the whole new array with the new adding elements. It returns undefines if the array is empty and this push() method is only works on array.

Example:

const friends= ['Bill gates', 'Jeff Bezos', 'Donald Trump', 'Barack Obama'];const count = friends.push('Samiul');
console.log(count);
It returns the total length of the array and it is:5
console.log(friends);
After push the elements the final result is : Array ['Bill gates', 'Jeff Bezos', 'Donald Trump', 'Barack Obama','Samiul']

Thank You for reading my article. If You like my article please Follow me on Linkedin.

--

--