Javascript

Introduction to Javascript

JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Firefox, Chrome, Opera, and Safari.

Before you continue you should have a basic understanding of the following: HTML / XHTML.

What is JavaScript?

  • JavaScript was designed to add interactivity to HTML pages
  • JavaScript is a scripting language
  • A scripting language is a lightweight programming language
  • JavaScript is usually embedded directly into HTML pages
  • JavaScript is an interpreted language (means that scripts execute without preliminary compilation)
  • Everyone can use JavaScript without purchasing a license.

Are Java and JavaScript the same?

NO!

Java and JavaScript are two completely different languages in both concept and design!

Java (developed by Sun Microsystems) is a powerful and much more complex programming language – in the same category as C and C++.


What can a JavaScript do?

  • JavaScript gives HTML designers a programming tool – HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small “snippets” of code into their HTML pages
  • JavaScript can put dynamic text into an HTML page – A JavaScript statement like this: document.write(“<h1>” + name + “</h1>”) can write a variable text into an HTML page
  • JavaScript can react to events – A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element
  • JavaScript can read and write HTML elements – A JavaScript can read and change the content of an HTML element
  • JavaScript can be used to validate data – A JavaScript can be used to validate form data before it is submitted to a server. This saves the server from extra processing
  • JavaScript can be used to detect the visitor’s browser – A JavaScript can be used to detect the visitor’s browser, and – depending on the browser – load another page specifically designed for that browser
  • JavaScript can be used to create cookies – A JavaScript can be used to store and retrieve information on the visitor’s computer

If you have seen anything interactive on a website like a pop-up-window calculation, some web counters and even some navigation systems then you have probably seen JavaScript.JavaScript has changed from being a language which develops web sites to a language which destroys them. This is because there are severa JavaScript websites which have thousands of scripts for download. These are generally involve things which do not benefit a website at all, like status bar effects and scrolling text which do not add much to a website.

JavaScript must not be confused with Java it is not Java. Java is a completely different programming language to Java Script. It is generaly used for text effects and games, although there are some JavaScript games around.

So why would you use or learn JavaScript? JavaScript can allow you to create new things on your website that are both dynamic and interactive, allow us to do things like find out some information about a user check that forms have been filled in correctly, rotate images, make random text, do calculations and many other things.

In this tutorial we are assuming that you understand HTML.If you don’t know HTML go to our HTML section.


What is JavaScript?

JavaScript (also called JScript) is a scripting language with the primary aim of giving life to our web pages.It is very powerful, flexible, and easy to learn.
JavaScript is: An interpreted language.This means that the code is executed straight away by an interpreter, which is built into web browsers, some web servers and Antechinus JavaScript Editor. JavaScript is sometimes used instead of VBScript for customizing applications.
An object-Oriente based language. You can create your new objects in JavaScript (or use the predefined ones), but not by inheriting from existing objects like fully-fledged object-oriented languages (C#, C++ or Java).
Not Java. Although JavaScript resembles languages like Java, C and C++, it is a language of its own.
Loosely typed. Languages like C# or C++ require that you declare the data type of the variables you are using. JavaScript does not. Most functions (for example, alert() ) will happily accept variables of different types and if needed convert them on the fly from one type to another.
Meant for “client-side” scripting. When visitors come to your web pages spiced with JavaScript, the code will executes on their machines. By comparison, PHP code will executes on the web server (“server-side” scripting) to output the HTML code, which is then fed to visitor’s web browsers.

Your First JavaSscript Code Example

<html>
 <body>
   <script type="text/javascript">
     <!--
     document.write("Vyom Technosoft!")
      //-->
   </script>
 </body>
</html>
Output
Vyom Technosoft!
Our first steps tell to the browser we were using a script with <script> tag. Next we set the type of scripts equal to “text/javascript”, which you may notice that doing this is similar to the way you specify in CSS, which is “text/css”.Next we added an optional HTML comment that surrounds our Javascript code. If a browser do not support Java Script, then it will not display our code in plain text to the user! The comment was ended with a “//–>” because “//” signifies a comment in Javascript, so we add that to prevent a browser from reading the end of the HTML comment in as a piece of Javascript code.

Javascript document.write

The final step of our script was to use a function that was called document.write which writes a string into our HTML document. document.write can be used to write text, HTML, or a little of both. We passed the famous string of text to the function to spell out “Vyom Technosoft!” which was printed to the screen.Do not worry if you do not completely understand how document.write works, as we will be discussing functions in a later section of the our Academic Tutorial.

Script

Looking at our Java Script above code given, mark that there is no semicolon (;) at the end of the statement “document.write(Vyom Technosoft!)”. Why? Because Javascript does not require that you use semicolons(;) to signify the end of each statement.If you are well experienced programmer and prefer to use semicolons, feel free to do so. Javascript will not malfunction from ending semicolons. The only time where it is necessary to use a semicolon is when you choose to smash or add two statements onto one line(i.e. two document.write statements on one line).
DOWNLOAD SOLUTION HERE