String length Property - Javascript String

Javascript examples for String:length


The length property returns the length of number of characters.

The length of an empty string is 0.

Return Value:

The length of a string

The following code shows how to return the number of characters in a string:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {/*from   w  w w.  ja  v a  2s  . c o m*/
    var str = "Hello World!";
    var n = str.length;
    document.getElementById("demo").innerHTML = n;


Related Tutorials