include js code example

Example 1: include script in html

<script type="text/javascript" src="/path/to/script.js"></script>

Example 2: include js in html

<html>
    <head>        
    </head>
    <body>
    
        <script type="text/javascript" src=es4.js></script>
           
    </body>
        
</html>

Example 3: javascript string includes

'Blue Whale'.includes('blue')  // returns false

Example 4: string contains in javascript

const string = "foo";
const substring = "oo";

console.log(string.includes(substring));

Example 5: javascript contains substring

var str = "We got a poop cleanup on isle 4.";
if(str.indexOf("poop") !== -1){
	alert("Not again");
}
//use indexOf (it returns position of substring or -1 if not found)

Example 6: how to add script in html head

<script src="script.js" defer></script>

<!--just add defer attribute so script will execute at last-->