Where to Insert JavaScript
Header or Body, use
<script> ... </script>1
2
3<script>
function myFunction() {}
</script>External File or URL, use
<script src="..."></script>1
2<script src="/js/myScript.js"></script>
<script src="https://www.dummy.com/js/myScript.js"></script>
JavaScript Output
- to Document:
document.write("...") - to Element:
document.getElementById("elementName").innerHTML = ... - to Alert Window:
window.alert(...);alert(...) - to Console:
console.log(...)
JavaScript Syntax
I know C, so nothing new
JavaScript Statements
- “;” is not required, but recommended
- line break after operator?????
- use
functionas code blocks - keywords:
break,continue,do ... while,for,if ... else,return,switchsimilar to Ctry ... catchsimilar to javadebugger: Stops the execution of JavaScript, and calls (if available) the debugging functionfunction,varexplained above
JavaScript Comments
Nothing new here