JavaScript

JavaScript

What is JavaScript?

JavaScript is a scripting or programming language that allows you to implement complex features on web pages, every time a web page does more than just sit there and display static information for you to look at displaying timely content updates, interactive maps, animated 2D/3D graphics, scrolling video jukeboxes, etc. you can bet that JavaScript is probably involved. It is the third layer of the layer cake of standard web technologies, two of which (HTML and CSS).

Examples of JavaScript is the browser:

  1. Slideshows.
  2. Forms.
  3. Reload part of page.
  4. Filtering data.

Scripts

Writing a script

First, you need to define the task you want to achieve.

To design a script you split the goal out into a series of tasks that are going to be involved in solving this puzzle. This can be represented using a flowchart. You can then write down individual steps that the computer needs to perform in order to complete each individual task (and any information it needs to perform the task), rather like writing a recipe that it can follow.

Flowchart example:

Flowchart

Variables

Rules for naming variables:

  1. The name must begin with a letter, dollar sign ($),or an underscore (_). It must not start with a number.

  2. The name can contain letters, numbers, dollar sign ($), or an underscore (_). Note that you must not use a dash(-) or a period (.) in a variable name.

  3. You cannot use keywords or reserved words. Keywords are special words that tell the interpreter to do something. For example, var is a keyword used to declare a variable. Reserved words are ones that may be used in a future version of JavaScript.

  4. All variables are case sensitive, so score and Score* would be different variable names, but it is bad practice to create two variables that have the same name using different cases.

  5. Use a name that describes the kind of information that the variable stores. For example, firstName might be used to store a person’s first name, lastNarne for their last name, and age for their age.

  6. If your variable name is made up of more than one word, use a capital letter for the first letter of every word after the first word. For example, firstName rather than firstname* (this is referred to as camel case). You can also use an underscore between each word (you cannot use a dash).

Arrays

Examples:

JS ARRAY

Arrays

EXPRESSIONS

  1. Expressions that just assign a value to a variable.

Example:

 var color = 'beige';
  1. Expressions that use two or more values to return a single value.

Example:

 var area = 3 * 2;

Operators

Example:

Operators

Arithmetic operators example:

Operators

Functions

Function

What is a function?

Declaring a function

Calling a Function

Calling a Function

References:

Main page