Get DevWP - WordPress Development Theme

JavaScript Syntax

JavaScript Syntax like other coding languages, refers to a set of rules on how you will write your code. Consider it like the grammar of a written/spoken language. Using the correct syntax is important because it will ensure that the results you get in the browser are what you expect to see.

While learning JavaScript, you will be getting yourself started in a much deeper level of programming using things like:

  • variables
  • functions
  • statements
  • operators
  • data types
  • objects
  • and more

These are part of what make dynamic programming possible and are often found in other complex langauges like PHP, Python, Java and others.

JavaScript Code Example


<script>
document.write("JavaScript is Awesome");
</script>

Let’s explain the code above.

The HTML <script></script> opening and closing tags tell the web browser to expect JavaScript. You also might see in older code examples type="text/javascript" used as an attribute in the starting <script> tag which specifies the type of text to expect but this is no longer needed since HTML5 expects JavaScript to be the default language used for the <script></script> tags.

The next part document.write("JavaScript is Awesome"); is used to write text to a web page. It’s just one way to accomplish this as you will see in other JavaScript Tutorials here on PixemWeb.

Where to Place your JavaScript Code?

Just like CSS, you can place your JavaScript code in 3 different places:

  1. In the <head></head> section of your HTML Document
  2. In the <body></body> section of your HTML Document
  3. In an external file linked to in the <head></head> section of your HTML Document. This is preferred


View Our Themes