Javascript: fourth lesson |
In the previous lessons, I explained the main
principles about Javascript. We talked about objects,
properties, methods and events. However Javascript is a
programming language, and now we have to observe closely
the Javascript language's structure.Variables and LiteralsIn the third lesson we talked about variables as they were some 'black box' which contain something. However there are some rules to handle variables:
Literals unlike variables, are fixed values. Literals may be: integers, booleans and strings. Integers may be decimals, hexadecimals or octals (e.g., 36, 0xfff, -45 and so on). Boleans may be: 'true' or 'false'. Strings are zero or more characters enclosed in double (") or single (') quotes (e.g., "sun", "2home$", '/%44ssbbccddaa.23-4' and so on). A little interesting thing: Escaping Characters. Escaping characters are characters which may be enclosed inside of strings. These characters begin with a "\". The "\n" escaping character for example, means new line. So, if you use a string like this: "This string is composed by: \n 2 lines..." The result will be: This string is composed by: 2 lines... Here a list of escaping characters:
For example, if you want to use this string: ' "this is a string" ', you have to write so: "\"this is a string\"". OperatorsThere are several operators: assignment, comparison, arithmetic, bitwise, logical, string and special operators. You can use operators between 2 operands, or you can just use one operand and one operator (or vice versa one operator and one operand). For example, "=" is the assignment operator to assign a value to a certain variable: var1 = "hello!" var1 is the first operand, "=" is the operator and "hello!" is the second operand. There are a lot of operators, and I am not going to show you all of them. Just I'm going to explain the commonest of them. Assignment operators
Comparison operators
Arithmetic operators
Logical operators
These operators are especially used inside of conditional expressions. We will observe them closely later...(if these things are too much complicated, don't worry, you will able to understand them later, when we will see some examples of scripts). |
Index Home Back About Contact us!
Copyright (c) 1998-2006 Wowarea