JavaScript/Basic JavaScript

Basics

 * JavaScript is a popular web-page scripting language, and is supported by almost every browser.
 * It adds interactivity to web-technology pages.
 * You can use editing tools on your device or within supporting software.
 * JavaScript can work with the user's (client) resources or server resources.
 * It is easy to learn the basics.

Step One: HTML & Scripts
Video Resources: Javascript 1 To start off with, the  tag tells the browser that whatever comes between that tag and the coming   tag is script, and the   tells it that it is JavaScript. Similarly, to use VBScript, you might use   instead of. For the purposes of this course, though, you should only ever need to use the JavaScript tag.

It is also important to note that the  tag is case sensitive. What this means is if you use lowercase letters in the tag, all the letters in the tag must be lowercase, and uppercase if you use any uppercase. For example, if you wrote  Not only would you waste a lot of time typing, but you would also confuse your browser.

You are probably wondering when I'm going to explain the rest of what you did. Well,  is the JavaScript standard for writing text to the browser window. The 'document' clause refers to the HTML webpage (termed a document) as a whole; what follows (' ') is a command for the document object to carry out. In this case, you told the page to write the classic " " to the screen.

Comments
.

Step Two: Variables
One of the things JavaScript is used for is the manipulation of data. In JavaScript, pieces of data can be stored either in variables or arrays.

Variables are declared using the var keyword: var numValue; var textValue; var binaryValue; and can be given values when they are created: var numValue = 3; var textValue = "This is text."; var binaryValue = true; Multiple variables can even be declared at the same time: var numValue = 3, textValue = "This is text.", binaryValue = true; Variables in JavaScript are weakly typed, meaning that the types of individual variables are not determined by the programmer. Unlike many languages, JavaScript only provides a generic var rather than separate types for integers, floating point numbers, characters, and strings. For example, in the statement var x = 0; it is fairly obvious to any individual reading the code that  is a number. However, if the statement x = x + "This is text that is probably not a number"; were to appear later in the code, JavaScript would change the variable to a text variable. This is one of the reasons that JavaScript is referred to as weakly typed; at any particular point in time, it is impossible to tell exactly what type a particular variable is.

String Operator
The string operator is used to concatenate two strings together. For example:

""

Conditional Operator
JavaScript also contains a conditional operator that assigns a value to a variable based on some condition.

The syntax would be:HTML

variablename = ( condition ) ? value1 : value2 value1 is the value of the expression if "condition" is fulfilled. value2 is its value in the case "condition" is not fulfilled. For example: ""

Semicolons
JavaScript require semicolons to be inserted to end statements and expressions. When you forget to add semicolon between commands, JavaScript adds it automatically so that it knows where to start the next command.

The rules of JavaScript automatic semicolon insertion are as follows:


 * 1) When the next line starts with a closing braces  , closing the current block
 * 2) When there is a   statement without a semicolon
 * 3) When there is a   statement without a semicolon
 * 4) When there is a   statement without a semicolon
 * 5) When there is a   statement without a semicolon
 * 6) When the final statement of the code is reached (The last line on the JavaScript file)