Stoc |
---|
...
JavaScript was originally developed by Brendan Eichof Netscape under the name Mocha, which was later renamed to LiveScript and finally to JavaScript. JavaScript code, much like other programming languages, is made up of statements which serve to make assignments, compare values and execute other sections of code.
...
...
JavaScript has some basic programming terms:
...
Note | ||
---|---|---|
| ||
For a complete list of reserved words, please check the TODO: reference to reserved words section. |
...
JavaScript is interpreted (executed) line-by-line as it is found in a piece of code (script)
...
JavaScript is case sensitive, meaning that capital letters are distinct from their lowercase counterparts.
...
...
All JavaScript keywords are lowercase. For example, when you use a feature like an if statement, make sure that you type if and not If or IF.
...
JavaScript uses the camel casing (mixed casing) naming convention for functions, methods and properties. If a name is one word, then the name is made of all lowercase characters. If more words are used to form a name, the first word is lowercase followed by the next word(s) which all start with a capital letter.
...
JavaScript applies these rules to the use of the whitespace in coding.
...
JavaScript ignores those characters that take up space on the screen without visual representation or without necessary meaning.
...
Code Block |
---|
x=x+1 |
or:
Code Block |
---|
x = x + 1 |
...
However, most operations other than simple arithmetic functions require a space to make their meaning clear.
...
Code Block |
---|
var s = 'This spacing is preserved.'; |
...
A semicolon indicates the end of a JavaScript statement. You can use a semicolon for:
...
Example:
Code Block |
---|
x = x + 1; |
...
Example:
Code Block |
---|
x = x + 1; y = y + 1; z = 0; |
...
Example:
Code Block |
---|
x = x + 1; y = y - 1; |
Note | ||
---|---|---|
| ||
You do not need to use a semicolon for the last statement of a method (script). |
...
JavaScript uses curly braces {} to group a list of statements together into one larger statement, known as a block statement.
...
Code Block |
---|
var count = 10; // holds a number of items |
...
Multiple line comments (similar to C programming) are enclosed between forward slash and asterix / at the beginning of the comment and an asterix and forward slash / at the end of the comment. Everything in between is ignored by the interpreter.
...
Example:
Code Block |
---|
var x = 2; |
...
Here are the main elements of JavaScript grammar:
...
Note | ||
---|---|---|
| ||
You should not use variables without first declaring them. Using a variable on the right-hand side of an assignment without first declaring it will result in an error. |
...
When you declare a variable you can do that with or without assigning a value to it.
...
Code Block |
---|
var x, y = 1, z; |
...
JavaScript knows two categories of data types:
...
These are primitive or basic data types, which contain one kind of data, for variables:
...
Note | ||
---|---|---|
| ||
When undefined and NULL data types are being compared, the result will be true. |
...
Composite data types are made up of strings, numbers, booleans, undefined values, null values and even other composite types. These are the three composite types:
...
Functions are used to keep code that performs a particular job in one place, making the code reusable. In Servoy, built-in functions are accessible from the method editor.
...
One of the major differences between JavaScript and other programming languages is that JavaScript is weakly typed. This means that the type of variable is inferred from the variable's content. As a result, the data type can change the moment you put data into the variable of another type than it previously contained.
...
Operator | Example | Description |
---|---|---|
== | a == b | Returns true if a and b are equal. |
!= | a != b | Returns true if a and b are not equal. |
> | a > b | Returns true if a is greater than b. |
< | a < b | Returns true if a is less than b. |
>= | a >= b | Returns true if a is greater than or equal to b. |
<= | a <= b | Returns true if a is less than or equal to b. |
...
Here is a tertiary statement:
...
Code Block |
---|
myString.length |
...
A JavaScript function is quite similar to a procedure or subroutine in other programming languages. A function is a discrete set of statements which perfom some actions. It may accept incoming values (parameters) and it may return an outgoing value.
...
The Servoy Solutions Object Model (SOM) and the W3C Document Object Model (DOM) are both object models.
...
An object model:
...
Here an overview of the Servoy SOM:
...
Here is a list of the JavaScript object references and how they apply to Servoy:
...