0% found this document useful (0 votes)
72 views

JavaScript Elmir Sut

This document is a graduation work from an IT student on the topic of JavaScript. It provides an introduction to JavaScript, comparing it to Java, and covers getting started topics like using the web console and scratchpad. The document discusses JavaScript basics like variables and data types. It also covers arrays, literals, and concludes by discussing whether JavaScript is freely available, elegant, and useful.

Uploaded by

Dila Selamoglu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

JavaScript Elmir Sut

This document is a graduation work from an IT student on the topic of JavaScript. It provides an introduction to JavaScript, comparing it to Java, and covers getting started topics like using the web console and scratchpad. The document discusses JavaScript basics like variables and data types. It also covers arrays, literals, and concludes by discussing whether JavaScript is freely available, elegant, and useful.

Uploaded by

Dila Selamoglu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Graduation work from IT

Topic: JavaScript

Professor:

Student:

Sabaheta ogi, prof.

Elmir ut, IV grade

Zenica, 2016.
Content:
1. Introduction.........................................................................................................................3

1.1. What is JavaScript..........................................................................................................3


1.2. JavaScript and Java........................................................................................................3
2. Elaboration..........................................................................................................................5
2.1. JavaScript and the ECMAScript specification.............................................................5
2.2. JavaScript documentation versus the ECMAScript specification ..............................5
2.3. Getting started with JavaScript....................................................................................6
2.3.1. The Web Console...................................................................................................6
2.3.2. Scratchpad..............................................................................................................7
2.3.3. Basics.....................................................................................................................8
2.3.4. Variables ................................................................................................................8
2.3.5. Declaring variables.................................................................................................8
2.4. Data structures and types..............................................................................................9
2.4.1. Data types...............................................................................................................9
2.4.2. Converting strings to numbers................................................................................9
2.5. Literals........................................................................................................................10
2.5.1 Array literals...........................................................................................................10

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 is a cross-platform, object-oriented scripting language. It is a small and lightweight


language. Inside a host environment (for example, a web browser), JavaScript can be connected to
the objects of its environment to provide programmatic control over them.

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.

2.2. JavaScript and Java


JavaScript and Java are similar in some ways but fundamentally different in some others. The
JavaScript language resembles Java but does not have Java's static typing and strong type
checking. JavaScript follows most Java expression syntax, naming conventions and basic controlflow constructs which was the reason why it was renamed from LiveScript to JavaScript.

In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a


runtime system based on a small number of data types representing numeric, Boolean, and string
values. JavaScript has a prototype-based object model instead of the more common class-based
object model. The prototype-based model provides dynamic inheritance; that is, what is inherited
can vary for individual objects. JavaScript also supports functions without any special declarative
requirements. Functions can be properties of objects, executing as loosely typed methods.

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.

(Table 1 shows comparison between JavaScript and Java)

2. Elaboration
2.1. JavaScript and the ECMAScript specification
4

JavaScript is standardized at Ecma International the European association for standardizing


information and communication systems (ECMA was formerly an acronym for the European
Computer Manufacturers Association) to deliver a standardized, international programming
language based on JavaScript. This standardized version of JavaScript, called ECMAScript,
behaves the same way in all applications that support the standard. Companies can use the open
standard language to develop their implementation of JavaScript. The ECMAScript standard is
documented in the ECMA-262 specification. See New in JavaScript to learn more about different
versions of JavaScript and ECMAScript specification editions.
The ECMA-262 standard is also approved by the ISO (International Organization for
Standardization) as ISO-16262. You can also find the specification on the Ecma International
website. The ECMAScript specification does not describe the Document Object Model (DOM),
which is standardized by the World Wide Web Consortium (W3C). The DOM defines the way in
which HTML document objects are exposed to your script. To get a better idea about the different
technologies that are used when programming with JavaScript, consult the article JavaScript
technologies overview.

2.2. JavaScript documentation versus the ECMAScript specification


The ECMAScript specification is a set of requirements for implementing ECMAScript; it is useful
if you want to implement standards-compliant language features in your ECMAScript
implementation or engine (such as SpiderMonkey in Firefox, or v8 in Chrome).
The ECMAScript document is not intended to help script programmers; use the JavaScript
documentation for information on writing scripts.
The ECMAScript specification uses terminology and syntax that may be unfamiliar to a JavaScript
programmer. Although the description of the language may differ in ECMAScript, the language
itself remains the same. JavaScript supports all functionality outlined in the ECMAScript
specification.
The JavaScript documentation describes aspects of the language that are appropriate for a
JavaScript programmer.

2.3. Getting started with JavaScript


2.3.1. The Web Console

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:

(Picture 1 shows Console)

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.

(Picture 2 shows Scratchpad)

2.3.3. Basics
JavaScript borrows most of its syntax from Java, but is also influenced by Awk, Perl and Python.
7

JavaScript is case-sensitive and uses the Unicode character set.


In JavaScript, instructions are called statements and are separated by a semicolon (;). Spaces, tabs
and newline characters are called whitespace. The source text of JavaScript scripts gets scanned
from left to right and is converted into a sequence of input elements which are tokens, control
characters, line terminators, comments or whitespace. ECMAScript also defines certain keywords
and literals and has rules for automatic insertion of semicolons (ASI) to end statements. However,
it is recommended to always add semicolons to end your statements; it will avoid side effects. For
more information, see the detailed reference about JavaScript's lexical grammar.

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.

2.3.5. Declaring variables


You can declare a variable in three ways:
With the keyword var. For example, var x = 42. This syntax can be used to declare both local and
global variables.
By simply assigning it a value. For example, x = 42. This always declares a global variable. It
generates a strict JavaScript warning. You shouldn't use this variant.
With the keyword let. For example, let y = 13. This syntax can be used to declare a block scope
local variable. See Variable scope below.

2.4. Data structures and types


2.4.1. Data types
8

The latest ECMAScript standard defines seven data types:


-Six data types that are primitives:
Boolean. true and false.
null. A special keyword denoting a null value. Because JavaScript is case-sensitive, null is
not the same as Null, NULL, or any other variant.
undefined. A top-level property whose value is undefined.
Number. 42 or 3.14159.
String. "Howdy"
Symbol (new in ECMAScript 6). A data type whose instances are unique and immutable.
-and Object
Although these data types are a relatively small amount, they enable you to perform useful
functions with your applications. Objects and functions are the other fundamental elements in the
language. You can think of objects as named containers for values, and functions as procedures
that your application can perform.

2.4.2. Converting strings to numbers


In the case that a value representing a number is in memory as a string, there are methods for
conversion.

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

2.5.1 Array literals


An array literal is a list of zero or more expressions, each of which represents an array element,
enclosed in square brackets ([]). When you create an array using an array literal, it is initialized
with the specified values as its elements, and its length is set to the number of arguments specified.
If an array is created using a literal in a top-level script, JavaScript interprets the array each time it
evaluates the expression containing the array literal. In addition, a literal used in a function is
created each time the function is called.
Array literals are also Array objects. See Array and Indexed collections for details on Array
objects.

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.

3.2. Is JavaScript Elegant?


Yes and no. Ive written fair amounts of code in several programming languages from different
paradigms. Therefore, Im well aware that JavaScript isnt the pinnacle of elegance. However, it is
a very flexible language, has a reasonably elegant core, and enables you to use a mixture of objectoriented programming and functional programming.
Language compatibility between JavaScript engines used to be a problem, but isnt anymore,
partly thanks to the test262 suite that checks engines for conformance to the ECMAScript
specification. In contrast, browser and DOM differences are still a challenge. Thats why it is
normally best to rely on frameworks for hiding those differences.

3.3. Is JavaScript Useful?


The most beautiful programming language in the world is useless unless it allows you to write the
program that you need.
Considering the preceding list of what makes a language attractive, JavaScript is doing
remarkably well. It certainly is not perfect, but at the moment, it is hard to beatand things
are only getting better.

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

You might also like