Formatting text in JavaScript

We can format text in JavaScript using the following methods:

  1. bold () – makes text bold
  2. italics () – italicizes text
  3. fontcolor () – changes the color of the text to the specified color as an argument.
  4. fontsize () – changes the size of the text to the specified size as an argument.
  5. toLowerCase () – changes text to all lowercase letters.
  6. toUpperCase () – changes text to all upper case letters.

For example;

We create a variable greeting and format it accordingly:

<script language=”javascript”>

Var greeting=”Welcome to JavaScript Tutorial”
greeting=greeting.fontcolor(“red”);
greeting=greeting.bold();
greeting=greeting.fontsize(“10”);
greeting=greeting.italics();
document.write(greeting);

</script>

The Output