Introduction to JavaScript
What is a programming "Language"?
- Simply it is a formal (i.e. well-defined) language that is
unambiguous as much as possible at all levels. Where in English words may
have different meaning based on context, computers do not handle such
ambiguity well and so formal languages try to eliminate such ambiguity as
much as possible. The upside is that the rules for the languages' grammar
or the syntax of the language are very clearly defined, making it
easier to learn than a Human language.
- The purpose of the language is to instruct the computer, usually when
given some input, to perform operations on the given input, producing
some desired output.
- In that respect a program is like a recipe, ingredients (input) in,
something to eat out.
- Computers only understand very simple things at the lowest levels, like:
- Copy data from one place to another. (assignment)
- Do numeric operations, such as addition and multiplication.
(expressions)
- Compare two values and determine if they are the same or not or if one
is less or greater than the other. (conditionals,
Boolean logic)
- Jump around from one place to another in the program depending on the
outcomes of the above comparisons. (loops and functions)
- Computer languages attempt to abstract the simple things computers do to
a higher level to make things easier for the programmer. Some languages
do so better than others.
- Some languages may be described as higher or lower level.
This is usually meant to describe how close the syntax is the "lowest" level
language assembly or machine language (ML) which is the
native language of any computer and consists of very simple
instructions that individually usually do nothing more than one of the four
above things. Programming in assembly is usually regarded as tedious and
often difficult, making for more mistakes that cause program crashes, especially
for large programs. And so higher level languages were developed that made
making mistakes less likely allowed the incorporation of libraries and more
expressive code to abstract away common tasks that might take a lot of
effort to develop in a lower level language.
What is the "syntax" of a computer language?
It is the grammar, or rules for the language, just as English does, computer
languages have similar rules, but much more limited range of expression.
Often times programmers may describe the syntax of a programming language in
terms of Lego bricks. Things like statements in such languages are
like bricks that can then be snapped into a language anywhere a statement
would go, and in this way assembling a program can be like snapping Lego
bricks together. You have many different kinds of statements, but
any kind of statement can be snapped into a statement spot. When learning
a computer language it may be useful to employ this kind of mindset.
For this class we will learn JavaScript aka
ECMAScript. It is
incorporated into almost every browser, and also stand-alone as
interpreters/compilers such as node.js or
"node" and SpiderMonkey
or "js". One of the reasons for the choice of this language over others
is that it should not disadvantage anyone moving on to CS201/CS202 which
use C/C++ which are structurally similar, it is widely used in industry and
so there are a large number of free online informational resources and
coupled with a simple text editor and web browser, everyone already has a
development environment installed on their computer, making the cost of
entry into JavaScript development very low indeed.