JavaScript Elmir Sut
JavaScript Elmir Sut
Topic: JavaScript
Professor:
Student:
Zenica, 2016.
Content:
1. Introduction.........................................................................................................................3
3. Conclusion.........................................................................................................................11
3.1. Is JavaScript Freely Available?...................................................................................11
3.2. Is JavaScript Elegant?.................................................................................................11
3.3. Is JavaScript Useful?..................................................................................................11
References.............................................................................................................................12
1. Introduction
1.1. What is JavaScript?
2
JavaScript contains a standard library of objects, such as Array, Date, and Math, and a core set of
language elements such as operators, control structures, and statements. Core JavaScript can be
extended for a variety of purposes by supplementing it with additional objects; for example:
Client-side JavaScript extends the core language by supplying objects to control a browser and its
Document Object Model (DOM). For example, client-side extensions allow an application to place
elements on an HTML form and respond to user events such as mouse clicks, form input, and page
navigation.
Server-side JavaScript extends the core language by supplying objects relevant to running
JavaScript on a server. For example, server-side extensions allow an application to communicate
with a database, provide continuity of information from one invocation to another of the
application, or perform file manipulations on a server.
JavaScript is a very free-form language compared to Java. You do not have to declare all variables,
classes, and methods. You do not have to be concerned with whether methods are public, private,
3
or protected, and you do not have to implement interfaces. Variables, parameters, and function
return types are not explicitly typed.
Java is a class-based programming language designed for fast execution and type safety. Type
safety means, for instance, that you can't cast a Java integer into an object reference or access
private memory by corrupting Java bytecodes. Java's class-based model means that programs
consist exclusively of classes and their methods. Java's class inheritance and strong typing
generally require tightly coupled object hierarchies. These requirements make Java programming
more complex than JavaScript programming.
In contrast, JavaScript descends in spirit from a line of smaller, dynamically typed languages such
as HyperTalk and dBASE. These scripting languages offer programming tools to a much wider
audience because of their easier syntax, specialized built-in functionality, and minimal
requirements for object creation.
2. Elaboration
2.1. JavaScript and the ECMAScript specification
4
The Web Console shows you information about the currently loaded Web page, and also includes a
command line that you can use to execute JavaScript expressions in the current page.
To open the Web Console (Ctrl+Shift+K), select "Web Console" from the "Developer" menu,
which is under the "Tools" menu in Firefox. It appears at the bottom of the browser window.
Along the bottom of the console is a command line that you can use to enter JavaScript, and the
output appears in the pane above:
2.3.2. Scratchpad
6
The Web Console is great for executing single lines of JavaScript, but although you can execute
multiple lines, it's not very convenient for that, and you can't save your code samples using the
Web Console. So for more complex examples Scratchpad is a better tool.
To open Scratchpad (Shift+F4), select "Scratchpad" from the "Developer" menu, which is under
the menu in Firefox. It opens in a separate window and is an editor that you can use to write and
execute JavaScript in the browser. You can also save scripts to disk and load them from disk.
2.3.3. Basics
JavaScript borrows most of its syntax from Java, but is also influenced by Awk, Perl and Python.
7
2.3.4. Variables
You use variables as symbolic names for values in your application. The names of variables, called
identifiers, conform to certain rules.
A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($); subsequent
characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the
characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase).
You can use ISO 8859-1 or Unicode letters such as and in identifiers. You can also use the
Unicode escape sequences as characters in identifiers.
parseInt()
parseFloat()
parseInt will only return whole numbers, so its use is diminished for decimals. Additionally, a best
practice for parseInt is to always include the radix parameter. The radix parameter is used to
specify which numerical system is to be used.
An alternative method of retrieving a number from a string is with the + (unary plus) operator:
2.5. Literals
You use literals to represent values in JavaScript. These are fixed values, not variables that you
literally provide in your script. This section describes the following types of literals:
9
Array literals
Boolean literals
Floating-point literals
Integers
Object literals
RegExp literals
String literals
3. Conclusion
3.1. Is JavaScript Freely Available?
10
JavaScript is arguably the most open programming language there is: ECMA-262, its
specification, is an ISO standard. That specification is closely followed by many implementations
from independent parties. Some of those implementations are open source. Furthermore, the
evolution of the language is handled by TC39, a committee comprising several companies,
including all major browser vendors. Many of those companies are normally competitors, but they
work together for the benefit of the language.
References:
https://developer.mozilla.org/en-US/docs/Web/JavaScript
11
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Introduction
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types
12