Running Javascript

There are 3 ways you can run code

Embedding Inline
You can embed javascript directly inline using an attribute

<body onload="alert("message");"> 

Embedding script tags
This can be either in the <head> or in <bod>

<script type=text/javascript">
   function MyFun() {
      var myValue = documents.getElementById('myBox').value;
      if (myValue.length == 0) {
         alert("blank box");
   <input type="text" id="myBox">
   <input type="submit" value="Press" onclick="MyFun()"/>

Linking JS File

escape characters \" for double quotes

security prompt = allow active content to run on my computer
javascript runtime depends on the browser
has garbage collection
functions replace classes, constructors, methods
variables can be redefined at runtime (dynamic)
no compile check done only runtime checks (because it is loosely typed)
prototype instead of inheritance
any number starting with zero is an octal number
non zero numbers are true

confirm("A message box appears");
var return = prompt("What day is it today?");


// my comment 
/* multi-line */

syntax or run-time

© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited