10 Javascript Topic For new Javascript learner

1. The slice() Method

slice() extracts a part of a string and returns the extracted part in a new string.

The method takes 2 parameters: the start position, and the end position (end not included).

This example slices out a portion of a string from position 7 to position 12 (13–1):


var str = “Mango, Orange, Lichu”;
var res = str.slice(7, 13);


2. The substring() Method

substring() is similar to slice().

The difference is that substring() cannot accept negative indexes.

var str = “Apple, Banana, Kiwi”;
var res = str.substring(7, 13);


3. Rplacing String Content

str = “Please visit Microsoft!”;
var n = str.replace(“Microsoft”, “W3Schools”);

4. Converting to Upper and Lower Case

A string is converted to upper case with toUpperCase():

var text1 = “Hello World!”; // String
var text2 = text1.toUpperCase(); // text2 is text1 converted to upper

5. The concat() Method

concat() joins two or more strings:

var text1 = “Hello”;
var text2 = “World”;
var text3 = text1.concat(“ “, text2);

6. String.trim()

The trim() method removes whitespace from both sides of a string:

var str = “ Hello World! “;



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