A Simple Overview of Javascript

A Summary of Chapter 1-7

Javascript, assuming you know another programming language and puts all the information in one place (just ctrl+f to find!). Javascript has nothing to do with Java, is dynamically typed and has C-like syntax.

Enabling Javascript

Include javascript inside HTML:

<script> tag

Reference external file:

<script src="http://example.com/script.js">

Uses of JavaScript

JavaScript is most commonly used as a client side scripting language. This means that JavaScript code is written into an HTML page. When a user requests an HTML page with JavaScript in it, the script is sent to the browser and it’s up to the browser to do something with it.

JavaScript Implementations

  1. The Core (ECMAScript)
  2. The Document Object Model (DOM)
  3. The Browser Object Model (BOM)

The ECMAScript

ECMAScript is simply a description defining all properties, methods, and objects of a scripting language.Syntax Types:

  • Statements
  • Keywords
  • Reserved Words
  • Operators
  • Objects

The Document Object Model (DOM)

  • The Document Object Model describes methods and interfaces for working with the content of a web page.
  • The DOM is a tree-based, language-independent API for HTML as well as XML.

 

The Browser Object Model (BOM)

The Browser Object Model describes methods and interfaces for interacting with the browser.

The windowobject represents an entire browser window:

  • Objects – document-anchors, forms, images, links, location, frames, history, location, navigator, screen.
  • Methods – moveBy(), moveTo(), resizeBy(), resizeTo(), open(), close(),…
  • Properties – screenX, screenY, status, defaultStatus, etc.

 

Programming uses of JavaScript

Variable names

  • The variable name must start with a letter or an underscore
    firstName or _myName
  • You can use numbers in a variable name, but not as the first character
    name01 or tuition$
  • You can’t use space to separate characters
    userName NOT user Name
  • Capitalize the first letter of every word except the first
    salesTax or userFirstName

To declare variables, use the keyword ‘var’ and the variable name:

var userName;
var userName = “Smith”;
var price = 100;

Functions

With functions, you can give a name to a whole block of code, allowing you to reference it from anywhere in your program. JavaScript has built-in functions for several predefined operations. Here are three some functions.

alert(“message”);
confirm(“message”);
prompt(“message”);

User-Defined Functions

With user-defined functions, you can name a block of code and call it when you need it. You define a function in the HEAD section of a web page. It is defined with the function keyword, followed by the function name and any arguments.

function functionName(argument) {
statements;
}

Objects

JavaScript supports programming with objects. Objects are a way of organizing the variables. The different screen elements such as Web pages, forms, text boxes, images, and buttons are treated as objects.

Properties and Methods

Every object has its own properties and methods. Properties define the characteristics of an object.

Examples: color, length, name, height, width

Built-in Objects

Some of the built-in language objects of JavaScript offer more advanced operations such as:

  • Math – provides for math calculations
  • Date – provides date and time information
  • String – provides for string manipulation
 

Leave a comment