JavaScript language overview
JavaScript syntax, operators, and flow-control statements are similar to those in the C language. It includes if, else, switch, break, for, while, do, and return statements which behave almost identically to their C counter-parts. As a result, C programmers can easily read and modify most JavaScript scripts.
JavaScript is a loosely-typed language. Variables in JavaScript are more flexible than variables in C or Java. Variables do not need to be explicitly declared, and the same variable can store different data types at different points within a script. These types are number, string, Boolean value, array, object, function (which is actually an object itself), andnull. Operators automatically convert values between data types as necessary.
Variables can be local to a function or global to the entire JavaScript environment. Variable and object names may not contain spaces or punctuation other than "_" or "$". In addition, variable and object names can include numbers but must not begin with a number.
JavaScript does not have pointers and does not deal with memory addresses.
Common misconceptions about javaScript
If you've used JavaScript before, you have probably added scripts to a web page. It's important to clear up misconceptions some programmers may have about JavaScript when used outside the context of web pages:
- JavaScript is a general-purpose, cross-platform programming language. While it was developed for use in web-browsers, it has a number of features that make it useful for application configuration. It is easy to learn and use, the syntax is similar to C, it is object oriented, and it is widely documented.
- JavaScript is standardized. The language is also called ECMAScript, and the ECMA-262 standard defines the language (see http://www.ecma.ch/ecma1/STAND/ECMA-262.HTM). The basic syntax and semantics of the language are stable and standardized.
- When you use JavaScript in a web page, the objects you use are defined by the Document Object Model (DOM). These objects include window, document, form, and image. The DOM is not part of the JavaScript standard; nor is the DOM part of XDCscript.
- Other object models can be defined for use with JavaScript. Instead of the DOM, XDCscript often runs in the context of an "object model" containing one or more global objects; for example, configuration scripts are run in a context in which the global variable Program is defined.
- JavaScript is not a part of Java. These are two different languages that have similar names for historical marketing reasons. However, XDCscript does allow scripts to call arbitrary Java functions, including any method provided by the the standard Java Runtime Environment.
- For security reasons within web browsers, JavaScript does not provide built-in support for file services. However, by virtue of providing access to the Java Runtime Environment, XDCscript has full access to a complete (and standard) set of file-system services.
- RTSC Modules run JavaScript only on the host PC, UNIX, or Linux machine. JavaScript code is not run on the embedded target (yet).