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