Speaking JavaScript: An In-Depth Guide for Programmers by Axel Rauschmayer EPUB & PDF – eBook Details Online
- Status: Available for Free Download
- Author Name: Axel Rauschmayer
- Book Genre: Coding, Computer Science, Programming, Software, Technical, Technology, Unfinished
- Series Detail:
- ISBN # 9781449365035
- ASIN # 1449365035
- Edition Language: English
- Date of Publication: January 1, 2014
- PDF File Size: 11 MB
Basic JavaScript
This chapter is about “Basic JavaScript,” a name I chose for a subset of JavaScript that is
as concise as possible while still enabling you to be productive. When you are starting
to learn JavaScript, I recommend that you program in it for a while before moving on
to the rest of the language. That way, you don’t have to learn everything at once, which
can be confusing.
Background
This section gives a little background on JavaScript to help you understand why it is the
way it is.
JavaScript Versus ECMAScript
ECMAScript is the official name for JavaScript. A new name became necessary because
there is a trademark on Java (held originally by Sun, now by Oracle). At the moment,
Mozilla is one of the few companies allowed to officially use the name JavaScript because
it received a license long ago. For common usage, the following rules apply:
• JavaScript means the programming language.
• ECMAScript is the name used by the language specification. Therefore, whenever
referring to versions of the language, people say ECMAScript. The current version
of JavaScript is ECMAScript 5; ECMAScript 6 is currently being developed.
Influences and Nature of the Language
JavaScript’s creator, Brendan Eich, had no choice but to create the language very quickly
(or other, worse technologies would have been adopted by Netscape). He borrowed from
several programming languages: Java (syntax, primitive values versus objects), Scheme
and AWK (first-class functions), Self (prototypal inheritance), and Perl and Python
(strings, arrays, and regular expressions).
JavaScript did not have exception handling until ECMAScript 3, which explains why
the language so often automatically converts values and so often fails silently: it initially
couldn’t throw exceptions.
On one hand, JavaScript has quirks and is missing quite a bit of functionality (blockscoped variables, modules, support for subclassing, etc.). On the other hand, it has
several powerful features that allow you to work around these problems. In other lan‐
guages, you learn language features. In JavaScript, you often learn patterns instead.
Given its influences, it is no surprise that JavaScript enables a programming style that
is a mixture of functional programming (higher-order functions; built-in map, reduce,
etc.) and object-oriented programming (objects, inheritance).
Syntax
This section explains basic syntactic principles of JavaScript.
An Overview of the Syntax
A few examples of syntax:
// Two slashes start single-line comments
var x; // declaring a variable
x = 3 + y; // assigning a value to the variable `x`
foo(x, y); // calling function `foo` with parameters `x` and `y`
obj.bar(3); // calling method `bar` of object `obj`
// A conditional statement
if (x === 0) { // Is `x` equal to zero?
x = 123;
}
// Defining function `baz` with parameters `a` and `b`
function baz(a, b) {
return a + b;
}
Note the two different uses of the equals sign:
• A single equals sign (=) is used to assign a value to a variable.
• A triple equals sign (===) is used to compare two values (see “Equality Operators”
on page 14).
For More Read Download This Book
EPUB