Strings in JavaScript

Strings are treated as primitive types in JavaScript. But still we can use them like objects using the concept called as auto-boxing.

There are 2 types of String methods.

  1. Normal string methods – e.g. replace, search, match methods
  2. HTML helper methods – e.g. anchor(), bold(), fontcolor(), italics(), link(), small()

Examples on normal string methods

 

Converting the string to upper case or lower case

You can convert the string to lower case using “toLowerCase” method.

var city=”Brisbane”

console.log (“Lower case city is ” + city.toLowerCase());

You can convert the string to upper case using “toUpperCase” method.

var city=”Brisbane”

console.log (“Upper case city is ” + city.toUpperCase());

Finding the length of the string

You can find the length of string using “length” property.

var city=”Brisbane”

console.log (“Length of city is ” + city.length);

Below image shows all normal methods in action.

normal-string-methods

normal-string-methods

Examples on HTML string methods

Below image shows all HTML helper methods in action.

string-html-methods

string-html-methods

You may also like...