Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

JavaScript Syntax (JavaScript tutorial)

Hello guys morning to you all and welcome to this Tutorial post on Javascript. Like you all know i started my tutorial on JavaScript in my previous tutorial post and we looked at a brief JavaScript Overview. Now in this tutorial post am gonna be discussing JavaScript Syntax.

A JavaScript consists of JavaScript statements that are placed within the HTML tag in the web page.

You can place the

The

JavaScript Code

You can also read: Positioning (Css tutorial)

The Script tag takes two important attributes:
  • language: This attribute specifies what scripting language you are using. Typically it's value will be JavaScript. Although recent versions of HTML(and XHTML, its successor) have phased out the use of this attribute.
  • type: This attribute is what is now recommended to indicate the scripting language in use and its value should be set to text/javascript.
So your JavaScript segment will look like:

JavaScript Code

Your First JavaScript Code:
Let us write a simple JavaScript code that will print "Hello World".


We added an optional HTML comment that surrounds our code. This is to save our code from a browser that does not support JavaScript. The comment ends with a "//-->" and here "//" signifies a comment in JavaScript, so we add that to prevent the browser from reading the end of the HTML comment in as a piece of JavaScript code.
Next we call a function document.write which writes a string into the HTML document. This function can be used to write text, HTML, or both. So above code will produce the result below.

Hello World!

You can also read: Pseudo elements (Css tutorial)

Whitespace and Line Breaks:
JavaScript ignores spaces, tabs, and newlines that appear in JavaScript program.
Because you can use spaces, tabs, newlines freely in your program so you are free to format and indent your program in a neat and consistent way that makes the code easy to read and understand.

Semicolons are optional:
Simple statements in JavaScript are generally followed by semicolon character, just as they are in C, C++, and Java. JavaScript however allows you to omit this semicolon if your statements are each placed on separate line. For example, the following codes could be written without semicolons


But when formatted in a single line as follows, the semicolons are required:


Note: It is a good programming practice to use semicolons.

You can also read: Visibility (Css tutorial)

Case Sensitivity:
JavaScript is a case sensitive language. This means that language keywords, variables, function names, and any other identifiers must be typed with a consistent capitalization of letters.
So identifiers Time, TIme, and TIME will have a different meaning in JavaScript.
Note: Care should be taken while writing your variable and function names in JavaScript.

Comments in JavaScript:
JavaScript supports both C-style and C++-style comments, thus:
  • Any text between a // and the end of the line is treated as a comment and is ignored by JavaScript.
  • Any text between the characters /* and */ is treated as a comment. This may span multiple lines.
  • JavaScript also recognizes the HTML comment opening sequence is not recognized by JavaScript so it should be written as //-->
Example:


Alright guys we have come to this tutorial post on JavaScript Syntax. Always feel free to ask your questions in areas you don't understand properly, and i promise to attend to your questions as soon as possible. 

This blog has a chat box that is meant for interaction, so you guys should always feel free to interact there and share ideas, or you can also interact in the comment box below.

Like our facebook page and subscribe with us to get our tutorial posts delivered directly to your emails. Also share this tutorial post on the various social media platforms available.

You can follow us on twitter 
You can follow us on google+ 
You can also follow us on pinterest  


This post first appeared on Web Design Tutorialz, please read the originial post: here

Share the post

JavaScript Syntax (JavaScript tutorial)

×

Subscribe to Web Design Tutorialz

Get updates delivered right to your inbox!

Thank you for your subscription

×