Syntax


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>

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


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


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


Comments

// my comment 
/* multi-line */



Errors
syntax or run-time




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

Next