JavaScript (JS) - is a dynamic computer programming language. It
is most commonly used as part of web browsers, whose implementations
allow client-side scripts to interact with the user, control the
browser, communicate asynchronously, and alter the document content that
is displayed. It is also being used in server-side programming, game
development and the creation of desktop and mobile applications.
JavaScript is a
prototype-based scripting language with dynamic typing and has
first-class functions. Its syntax was influenced by C. JavaScript copies
many names and naming conventions from Java, but the two languages are
otherwise unrelated and have very different semantics. The key design
principles within JavaScript are taken from the Self and Scheme
programming languages. It is a multi-paradigm language, supporting
object-oriented, imperative, and functional programming styles.
Features
Imperative and structured
JavaScript supports much of
the structured programming syntax from C (e.g., if statements, while
loops, switch statements, etc.). One partial exception is scoping:
C-style block scoping is not supported. Instead, JavaScript has function
scoping (although, block scoping using the let keyword was added in
JavaScript 1.7). Like C, JavaScript makes a distinction between
expressions and statements. One syntactic difference from C is automatic
semicolon insertion, which allows the semicolons that would normally
terminate statements to be omitted.
Dynamic
Dynamic typing
As in most scripting
languages, types are associated with values, not with variables. For
example, a variable x could be bound to a number, then later rebound to
a string. JavaScript supports various ways to test the type of an
object, including duck typing.
Object-based
JavaScript is almost entirely
object-based. JavaScript objects are associative arrays, augmented with
prototypes (see below). Object property names are string keys. They
support two equivalent syntaxes: dot notation (obj.x = 10) and bracket
notation (obj['x'] = 10). Properties and their values can be added,
changed, or deleted at run-time. Most properties of an object (and those
on its prototype inheritance chain) can be enumerated using a for...in
loop. JavaScript has a small number of built-in objects such as Function
and Date.
Run-time evaluation
JavaScript includes an eval
function that can execute statements provided as strings at run-time.
Functional
First-class functions
Functions are first-class;
they are objects themselves. As such, they have properties and methods,
such as .call() and .bind().[35] A nested function is a function defined
within another function. It is created each time the outer function is
invoked. In addition, each created function forms a lexical closure: the
lexical scope of the outer function, including any constants, local
variables and argument values, becomes part of the internal state of
each inner function object, even after execution of the outer function
concludes.[36]
Prototype-based
Prototypes
JavaScript uses prototypes
where many other object oriented languages use classes for inheritance.
It is possible to simulate many class-based features with prototypes in
JavaScript.
Functions as object
constructors
Functions double as object
constructors along with their typical role. Prefixing a function call
with new will create an instance of a prototype, inheriting properties
and methods from the constructor (including properties from the Object
prototype). ECMAScript 5 offers the Object.create method, allowing
explicit creation of an instance without automatically inheriting from
the Object prototype (older environments can assign the prototype to
null). The constructor's prototype property determines the object used
for the new object's internal prototype. New methods can be added by
modifying the prototype of the object used as a constructor.
JavaScript's built-in constructors, such as Array or Object, also have
prototypes that can be modified. While it is possible to modify the
Object prototype, it is generally considered bad practice because most
objects in JavaScript will inherit methods and properties from the
Object prototype and they may not expect the prototype to be modified.
Functions as methods
Unlike many object-oriented
languages, there is no distinction between a function definition and a
method definition. Rather, the distinction occurs during function
calling; when a function is called as a method of an object, the
function's local this keyword is bound to that object for that
invocation.
Implicit and Explicit
Delegation
JavaScript is a Delegation
Language.
Functions as Roles (Traits and
Mixins)
JavaScript natively supports
various function based implementations of Role patterns like Traits and
Mixins. Such a function defines additional behavior by at least one
method bound to the this keyword within its function body. A Role then
has to be delegated explicitly via call or apply to objects that need to
feature additional behavior that is not shared via the prototype chain.
Type Composition and
Inheritance
Whereas explicit function
based delegation does cover composition in JavaScript, implicit
delegation already happens every time the prototype chain is walked in
order to e.g. find a method that might be related to but is not directly
owned by an object. Once the method was found it gets called within this
object's context. Thus inheritance in JavaScript is covered by a
delegation automatism that is bound to the prototype property of
constructor functions.
Miscellaneous
Run-time environment
JavaScript typically relies on
a run-time environment (e.g. a web browser) to provide objects and
methods by which scripts can interact with the environment (e.g. a
webpage DOM). It also relies on the run-time environment to provide the
ability to include/import scripts (e.g. HTML <script> elements). This is
not a language feature per se, but it is common in most JavaScript
implementations.
Variadic functions
An indefinite number of
parameters can be passed to a function. The function can access them
through formal parameters and also through the local arguments object.
Variadic functions can also be created by using the apply method.
Array and object literals
Like many scripting languages,
arrays and objects (associative arrays in other languages) can each be
created with a succinct shortcut syntax. In fact, these literals form
the basis of the JSON data format.
Regular expressions JavaScript also supports regular expressions in a manner similar to Perl, which provide a concise and powerful syntax for text manipulation that is more sophisticated than the built-in string functions.
|
|
Audrey Josh P.
Ricalde [email protected] |