1. Computing

JavaScript Variables and Operators

1. Introduction


To be able to understand how JavaScript works we'll first consider how programming languages work. Once you understand the basics you will be able to build on that knowledge to create interesting JavaScripts that can greatly enhance your visitor's experience of your site by allowing them to interact with your page in a variety of ways. One of the simplest interactions is to take one or more values entered into a form on the page, perform a calculation using those values, and then update the page with the result of that calculation. Calculations are also needed to produce more advanced interactions such as moving elements around on the page, changing the way that the page looks, or dynamically updating the page content with new information.

The core of any language whether spoken or used by computers is its syntax. This provides a set of rules that must be followed when you use that language. While spoken languages often have many exceptions to the various syntax rules, computer languages are much stricter in requiring the rules to be followed. Computers are not as smart as people and so need to be told exactly what to do step by step. While a person may be able to interpret instructions so as to work out what to do when you leave out a step in the instructions, a computer will follow your instructions exactly as written. Understanding the syntax rules that the computer will use to interpret your instructions is essential to instructing the computer correctly in what you want it to do.

In any language there are two fundamental "parts of speech". In spoken languages these are called nouns and verbs. In many programming languages including JavaScript they are called variables and operators.

We'll explore several key concepts related to variables and operators in this series, such as

  • How to define variables in JavaScript as well as some of the types of variables you can create.
  • How to use operators with numbers and text strings.
  • What happens when you combine different types of variable together.

This tutorial first appeared on www.felgall.com and is reproduced here with the permission of the author.

  1. About.com
  2. Computing
  3. JavaScript
  4. Javascript Tutorials
  5. Learn Modern JavaScript
  6. 1. Variables and Operators
  7. JavaScript Variables and Operators

©2014 About.com. All rights reserved.