Pages

Thursday, November 13, 2014

JavaScript Intro



  • JavaScript is one of the most popular programming languages in the web development world and is also called a scripting language.
  • JavaScript can be used to change the HTML elements.
  • JavaScript uses DOM(Document Object Model) which is a standard for accessing the HTML elements.
  • JavaScript can be used to change the style of HTML elements.
  • JavaScript is often used to validate the input fields of HTML forms, meaning to perform client-side validations.
JavaScript in <script>

  • Syntactically JavaScript must be inserted between the tags
    • <script> ... </script>
  • <script> means start of JavaScript code.
  • </script> means end of JavaScript code.

JavaScript in <head> and <body>

  • JavaScript code can be used in either <head> and <body> elements or in both.
  • We can use <script> any number of times in a HTML page.
  • Good Practice : Separating HTML and JavaScript and putting all JS code in one place is always a good habit.
  • Normally, JavaScript is used to execute upon an event in a HTML page like a Button press.


JavaScript as External File

  • JavaScript apart from HTML file can also be placed in a separate file, t
    he extension of such file would be ".js".
             syntax : <script src = "myscript.js"></script>