Basics of Javascript

Basics

This section will cover background basics and skills you will need to begin to add JavaScript to your web pages. Note : Javascript code is different from Java code.

To help you build a conceptual foundation, the following subsections will concentrate on a particular notion of JavaScript. This will give you a working knowledge of the language. If you are new to programming and scripting, it is a good idea to take notes as you go through the sections.

Object Orientation is an overview of the philosophical structure behind the JavaScript.
Scripting Language introduces the notion of a scripting language and outlines its strengths, weaknesses, and best applications.

——————————————————————————–

Object Orientation is a concept that has been around the programmer zeitgeist since the 1960s. Only recently has it begun to have a commercial influence. With an object approach, components are created that have distinct characteristics; components interact with other components based on these distinct characteristics.

Supporters of this approach say it is more flexible and powerful than the traditional approach by creating an environment in which code can be created faster and debugging of a code is simpler.

Detractors note that JavaScript is not a true and full object compliant language; however, they do agree it follows the basic philosophy.

Still, objects are at the core of JavaScript.

Objects have particular attributes.

The attributes here work like adjectives. These are termed properties. Example: an object has a size, name, and a text value.
Other attributes function like verbs. These are termed methods. Example: an object has the potential to display a text message, record information, or create an alert box.
The object also functions as a template. When using an object, an instance is created of the object and will work with the instance. Example: when you create an instance of the window object, you can name it ‘controlwindow’ and utilize it in your script.
A good way to think about the object approach is to consider it a collection of Scalextric pieces. Each particular piece can serve a different purpose, but if you combine them, you will inevitably end up with many different projects.

Scripts function very much in the same way to computers; they are raw and un-compiled. Some scripts always stay the same in a system and are used to run basic maintenance tasks that are repetitive. You may have encountered this type of script in the macros of your spreadsheet.

Scripting Language

Many types of scripting languages exist. For example PHP (which is most popular in writing website scripts) – However, we will concentrate on one of the most widely used in the web client environment: JavaScript.

Scripting languages are different in of themselves, but share one trait: they cannot run by themselves. They all require an interpretive program, such as a web browser, to translate the textual script into commands the computer can execute.

A JavaScript script contains several elements, including:

Objects- methods and properties, known as the basic building blocks of the script.
Operators- Work like mathematical verbs. They commit actions, i.e., assign, compare, compute and evaluate values. They form expressions by incorporating themselves with objects and variables.
Variables- Work as containers for storing data. This datum in a variable can be calculated, tested, or passed along to other variables.
Functions- Work by performing an action. Think of these like a paragraph, with its intricate set of phrases, or lines of instruction, directed at the computer to perform an action. Example: you might create a function that looks at a time recorded by an object, evaluates the time, and then performs an action if the time meets a set of criteria. Or you might create a function that displays a pop up window when the user performs a certain function.
Events and Event Handlers- These notice the actions of the reader once inside the browser. This feature is unique to JavaScript. It allows the scriptwriter to create interactive responses tailored to the readers’ actions, such as highlighting a hyperlink when the mouse pointer hovers over a link.
Arrays- these are variable sets saved under the same name. Two types used within JavaScript are link and image arrays.
JavaScript combines these pieces, creates an action and interaction, within your Web page.

——————————————————————————–

JavaScript Structure Guidelines

JavaScript works like the human language. It has syntax, a grammar, parts of speech and rules of structure. If you master the basic rules, you can deconstruct a script and figure out how it works and what it does.

Capitalization
White Space
Hard Returns
Punctuation Pairs
Capitalization

JavaScript is case sensitive. Pay attention to capitalization, this is a very common error when creating a JavaScript.

White Space
JavaScript ignores the spaces between the script texts. The web browser discards these spaces when deciphering a script; they are more for the human eye as space aids in making a script legible.

Example: xyxyxyxy=zxzxzxzxz+5 into the

If you add the spaces: xyxyxyxy = zxzxzxzxz + 5

Notice that the second script is identical except for the spaces. It will help someone other than the original writer of the script read it when changes need to be made.

Hard Returns

If JavaScript encounters a hard return (an invisible character generated after a return key is pressed) within a statement, it will ‘think’ it has come to the end of a statement. This will confuse the JavaScript and return an error message.

Example:

“This sentence will be displayed like this without pressing a hard return.”

Now notice this sentence pressing a hard return:

“This sentence will be

displayed like this when

hitting a hard return.”

An error message will occur because JavaScript is confused. It does not expect a hard return in the middle of the statement.

If you receive this error, it is a good idea to begin your troubleshooting looking for these hard returns; this too is a very common error.

Punctuation Pairs
Open punctuation symbols must have matching closing symbols.

( ); {}; []

This is another very common error in JavaScript. Be especially careful of how you use single and double quotation marks.

Example: If you write a sentence with quotes within quotes, be sure to pay attention to your marks.

“This will “produce” an error.”

JavaScript will interpret the first set as an ‘open and close’ pair because they are identical in ASCII. This is another very common error in JavaScript.

Here are some related terms for this article: javascript tutorials, JavaScript tutorials free, js tutorials, learn javascript for ajax and Javascript Tutorials For Beginners free.

Related posts :

  • Email extractor in javascript
  • Add colors to button
  • Javascript popup software
  • Floating Ad Javascript Popup maker script
  • Change background everyday
  • Background flash java script
  • Peel Away and Page peel ads.
  • Comments are closed.