JavaScript


#1

Does JavaScript have to be linked to html. If not, how do we start a JavaScript file.


#2

well, there is nodejs:

https://nodejs.org/en/

which run JS code.

Js is the only front-end scripting language for browsers, so its used a lot with html


#3

Sorry if this isn't what you meant,
But if you're looking into adding some Javascript to your HTML, you have two options:

Inline Javascript
You can add your JS script inside your HTML document, without linking to an external JS file.
This would look like:

<html>
<body>
  <div>
    <button onclick="myJavascriptFunction()">Trigger my Function!</button>
  </div>
<script>
function myJavascriptFunction() {
// do stuff
}
</script>
</body>
</html>

External Javascript file
You can start a JS file which will then be linked to your HTML document, like this:

HTML

<html>
<body>
  <div>
    <button onclick="myJavascriptFunction()">Trigger my Function!</button>
  </div>
<script src="myScript.js"></script> 
</body>
</html>

JS File (myScript.js)

function myJavascriptFunction() {
// do stuff
}

#4

It doesnt have to be linked to html file. You can copy paste it into browser console.