xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to check whether a string starts with the specified text in JavaScript
JavaScript Online Editor
Run Code
More JavaScript Sample Codes
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Check whether a string starts with the specified text in JavaScript</title> <!--Script tag is added to write JavaScript code inside it--> <script> let myString = "People loving fun use JavaScript to have fun over fun."; //startsWith() method is used to check whether the string starts with "JavaScript" let checkResult = myString.startsWith("JavaScript"); function myFunction() { if(checkResult == true) { document.getElementById("outPut").innerHTML = "The string starts with JavaScript."; } else{ document.getElementById("outPut").innerHTML = "The string does not start with JavaScript."; } } </script> </head> <body> <h1>Check Whether a String Starts With the Specified Text in JavaScript?</h1> <button onclick="myFunction()">Click here to see result</button> <p id="outPut"></p> </body> </html>