Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Get String Length in JavaScript</title> </head> <body> <script> var str1 = "This is a paragraph of text."; document.write(str1.length + "<br>"); // Prints 28 var str2 = "This is a \n paragraph of text."; document.write(str2.length); // Prints 30, because \n is only one character </script> </body> </html>