Web Designing & Java Script

businessunknownInternet και Εφαρμογές Web

12 Νοε 2013 (πριν από 3 χρόνια και 8 μήνες)

88 εμφανίσεις






Web Designing

& Java Script


1.

What’s relationship between JavaScript and ECMAScript?


JavaScript

was originally developed by

Brendan Eich

of

Netscape

under the name Mocha, later
LiveScr
ipt, and finally renamed to JavaScript.
[2]

In December 1995,

Sun Microsystems

and Netscape
announce
d JavaScript in a press release.
[3]

In March 1996,

Netscape Navigator

2.0 was out, featuring
su
pport for JavaScript.

Due to the widespread success of JavaScript as a client
-
side scripting language for web
pages,
Microsoft

developed a compatible dialect of the language, naming it

JScript

to avoid trademark
issues. JScript added new date methods to fix the non
-
Y2K
-
friendly methods in J
avaScript, which were
based on the Java

Date

class.
[4]

JScript was included in

Internet Explorer

3.0, released in August 1996.

Netscape delivered JavaScript to

Ecma International

for standardization and the work on the
specification, ECMA
-
262, began in November 199
6.
[5]

The first edition of ECMA
-
262 was adopted by the
Ecma General Assembly of June 1997. Several editions of the language standard have been published
since then.

JavaScript

is a

prototype
-
based

scripting language

that is

dynamic
,

weakly typed

and has

first
-
class
functions
. It is a

multi
-
paradigm

language, supporting

object
-
oriented
,
[5]

imperative
,
and
functional
[1]
[6]

programming
styles.

JavaScript was formalized in the

ECMAScript

language standard and is primarily used in the form
of

client
-
side JavaScript
, implemented as part of a

Web browser

in order to provide enhance
d

user
interfaces

and dynamic

websites
. This enables

programmatic

access to computational objects within a
host environment.

JavaScript's use in

applications

outside Web pages



for
example in

PDF

documents,

site
-
specific
browsers
, and

desktop widgets



is also significant. Newer and faster JavaScript

VMs
and frameworks
built upon them (
notably

Node.js
) have also increased the popularity of JavaScript for server
-
side web
applications.

JavaScript uses syntax influenced by that of

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.
[7]


2.

What are JavaScript typ
es?


The variable’s

data type

is the JavaScript scripting engine’s interpretation of the type of data that
variable is currently holding. A string variable holds a string; a number variable holds a number value, and
so on. However, unlike many other
languages, in JavaScript, the same variable can hold different types of
data, all within the same

application.

This is a concept known by the terms

loose typing

and

dynamic typing
,
both of which mean that a JavaScript variable can hold different data types

at different times depending on
context.

With a loosely typed language, you don’t have to declare ahead of time that a variable will be a string or a
number or a boolean, as the data type is actually determined while the application is being processed. If

you
start out with a string variable and then want to use it as a number, that’s perfectly fine, as long as the
string actually contains something that resembles a number and not something such as an email address. If
you later want to treat it as a strin
g again, that’s fine, too.

The forgiving nature of loose typing can end up generating problems. If you try to add two numbers
together, but the JavaScript engine interprets the variable holding one of them as a string data type, you
end up with an odd stri
ng, rather than the sum you were expecting. Context is everything when it comes to
variables and data types with

JavaScript.

This chapter covers the JavaScript

primitive data types of

string
,

boolean
, and

number
, as well as the
built
-
in functions for modif
ying values of these types. In addition, we’ll look at two special data types in
JavaScript,

null

and

undefined
, toward the end of the chapter. Along the way, we’ll explore escape
sequences in strings and take a brief look at Unicode. The chapter also delv
es into the topic of variables,
including what makes valid and meaningful variable identifiers.

Identifying Variables

JavaScript

variables have an identifier, scope, and a specific data type. Because the language is loosely
typed, the rest, as they say, is

subject to change without notice.

Variables in JavaScript are much like those in any other language; you use them to hold values in such a
way that the values can be explicitly accessed in different places in the code. Each has an identifier that is
uniqu
e to the scope of use (more on this later), consisting of any combination of letters, digits, underscores,
and dollar signs. An identifier doesn’t have a required format, other than it must begin with a character,
dollar sign, or underscore:


3.

How do you
convert numbers between different bases in JavaScript?


Number Bases and Leading Zeros

Join the Discussion

Questions? Comments?

One thing that can cause problems when writing Javascript is where h
ave a date that has been
entered and you are splitting it up to convert the separate day and month portions into numbers to
use for subsequent processing. Where these numbers are always entered as two digits the '08' and
'09' values often do not get conver
ted into numbers in the way that you would expect.
Using

parseInt('09')

givers you zero as the number that is returned rather than the 9 that you
expect.

Everyone is familiar with the base 10 (or decimal) way of counting where we have ten separate
symbols
to represent different values
-

0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. To get values greater than 9
(the largest number having a separate symbol) we start combining our symbols together and use 10
to represent the number one bigger than 9.

At this point you are

probably wondering what the above two paragraphs have in common and why I
have explained something so obvious as our numbering system the way that I have. The answer is
that the decimal numbering system is not the only possible numbering system and is in
fact not the
one that computers themselves use.

While we prefer to count using the decimal system, computers prefer to count using the binary (base
2) system. Binary has only two sysmbols to represent different values
-

0 and 1. To get values greater
than
1 we combine sysbols together the same way that we do in our decimal system and so in binary
10 represents the number one bigger than 1 (which is represented with 2 in our decimal system).
Even 1001 is not a very big number in binary as it can still be rep
resented with just one symbol in
decimal since it is the binary equivalent of 9.


4.

What does is

NaN function do


In floating
-
point calculations, NaN is not the same as

infinity
, although both are typically handled as
special cases in floating
-
point representations of real numbers as well as in floating
-
point operations. An

invalid operation is also not the same as an

arithmetic overflow

(which might return an infinity) or
an

arithmetic underflow

(which would return the smallest

normal number
, a

denormal number
, or

zero
).

IEEE 754

NaNs are represented with the exponential field fi
lled with ones (like infinity values), and some
non
-
zero number in the

significand

(to make them distinct from infinity values); this representation allows
the definition of multiple

distinct NaN values, depending on which bits are set in the significand, but also
on the value of the leading sign bit (not all applications are required to provide distinct semantics for those
distinct NaN values).

For example, a bit
-
wise example of a

IEEE floating
-
point standard

single precision (32
-
bit) NaN would
be:s111 1111 1axx xxxx xxxx xxxx xxxx xxxx

where

s

is the sign (most often ignored in

applications),

a

determines the type of NaN, and

x

is an extra payload (most often ignored in
applications). If

a

=

1, it is a

quiet NaN
; if

a

is zero and the payload is nonzero, then it is a

signaling
NaN
.
[3]

Floating point operations other than ordered comparisons normally propagate a quiet NaN (
qNaN
).
Floating point operations on a signaling NaN (
sNaN
) signal an invalid operation exception, the default
exception action is then the same as

for qNaN operands and they produce a qNaN if producing a floating
point result.

A comparison with a NaN always returns an

unordered result

even when comparing with itself. The
comparison predicates are either signaling or non
-
signaling, the signaling vers
ions signal an invalid
exception for such comparisons. The equality and inequality predicates are non
-
signaling
so

x

=

x

returning false can be used to test if

x

is a quiet NaN. The other standard comparison predicates
are all signaling if they receive a N
aN operand, the standard also provides non
-
signaling versions of
these other predicates. The predicate

isNaN(x)

determines if a value is a NaN and never signals an
exception, even if

x

is a signaling NaN.


5.

What is negative infinity?


Description

The
value of

Number.NEGATIVE_INFINITY

is the same as the negative value of the global
object's

Infini
ty

property.

This value behaves slightly differently than mathematical infinity:



Any positive value, including POSITIVE_INFINITY, multiplied by NEGATIVE_INFINITY is
NEGATIVE_INFINITY.



Any negative value, including NEGATIVE_INFINITY, multiplied by NEGATIVE_
INFINITY is
POSITIVE_INFINITY.



Zero multiplied by NEGATIVE_INFINITY is NaN.



NaN multiplied by NEGATIVE_INFINITY is NaN.



NEGATIVE_INFINITY, divided by any negative value except NEGATIVE_INFINITY, is
POSITIVE_INFINITY.



NEGATIVE_INFINITY, divided by any
positive value except POSITIVE_INFINITY, is
NEGATIVE_INFINITY.



NEGATIVE_INFINITY, divided by either NEGATIVE_INFINITY or POSITIVE_INFINITY, is NaN.



Any number divided by NEGATIVE_INFINITY is Zero.

Several JavaScript methods (such as the

Number

constructor,

parseFloat
, and

parseInt
)
return

NaN

if the value specified in the parameter is significantly lower
than

Number.MIN_VALUE
.

You might use the

Number.NEGATIVE_INFINITY

property to indicate an error condition
that returns a finite number in case of success.
Note, however, that

isFinite

would be more
appropriate in such a case.

Example

In the following example, the variable smallNumber is assigned a value that is smaller than
the minimum value. When the

if

statement executes, smallNumber has the value "
-
Infinity
", so smallNumber is set to a more manageable value before continuing.


6.

What
boolean operators does JavaScript support?


JavaScript is most commonly used as a client side scripting language. This means that
JavaScript code is written into an HTML page. When a user requests an HTML page with
JavaScript in it, the script is sent t
o the browser and it's up to the browser to do something
with it.

The fact that the script is in the HTML page means that your scripts can be seen and copied by whoever
views your page. Nonetheless, to my mind this openness is a great advantage, because th
e flip side is that
you can view, study and use any JavaScript you encounter on the WWW.

JavaScript can be used in other contexts than a Web browser. Netscape created server
-
side JavaScript as a
CGI
-
language that can do roughly the same as Perl or ASP. The
re is no reason why JavaScript couldn’t be
used to write real, complex programs. However, this site exclusively deals with the use of JavaScript in
web browsers.

If you don’t have any programming experience at all it’s best to start with some gentle JavaSc
ript
examples that teach you the basics. It might be a good idea to buy Negrino & Smith, “
JavaScript for the
World Wide Web
”, 4th edition, Peachpit

Press, 2001. It contains some very useful examples and though it
doesn’t treat advanced programming tricks, it will certainly help you get started. Of course this site also
offers plenty of help.

I can also recommend Jeremy Keith,

DOM Scripting: Web Design with JavaScript and the Document
Object Model
, 1st edition, Friends of Ed, 2005. This, too, is a book that doesn't delve too deeply into
technology, but gives non
-
programmers such as graphic designers/CSS wiz
ards an excellent overview of
the most common uses of JavaScript
-

as well as the most common problems.