forked from mrBliss/cpl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqa.txt
129 lines (104 loc) · 7.65 KB
/
qa.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
Q: Which programming language are we talking about today?
A: JavaScript, the language of the Internet.
Q: Why do you call it the /language of the Internet/?
A: JavaScript is the primary programming language than can be used in a web
browser. Whenever a site wants some client-side interactivity, JS is
/the/ tool in the box for this task.
Q: What do you mean by /client-side/?
A: Visiting a website involves two parties (or more), the visitor, i.e. the
client, and the visited website, i.e. the server.
First of all, the client requests a web page from the server. The server
then generates or retrieves the page to be sent to the client. The
generation of this page will be performed by a program, which, of course,
is written in a certain programming language. Programming languages used to
write the program on the server, commonly called `the web server', are
called server-side languages.
The second part of the interaction takes place in the browser of the
client. After receiving and rendering the web page, the web page would
remain completely static, were it not for client-side languages. Programs
written in a client-side language are sent along with the page to the
client and are executed in the browser when the page is loaded. They
provide a means to change the web page on the fly or to interact with the
user without requiring a new page to be loaded.
Q: Which other client-side languages are there?
[Is JavaScript the only language that can do that?]
A: There are several client side languages that can do quite the same. Examples
are Flash, Java, SilverLight, PerlScript, VBScript, Microsoft's JScript),
but JavaScript is the most widely used.
Every web browser supports the execution of JavaScript. JavaScript is used
by roughly 75% of all Internet websites [1].
[1]: http://dev.opera.com/articles/view/mama-key-findings/
(HTML, DHTML and CSS are also client side languages, but only used for mark-up)
Q: Why is JS the most popular?
A: JavaScript doesn't require a plugin to work. Others do, like Flash or Java.
Also, the JavaScript syntax looks very familiar to Object Oriented Programmers.
<ul>
<li>The implementation of JavaScript is also very easy: put the code in the HTML document and refer to it as a JavaScript script;
<li>The execution of JavaScript can happen offline;
<li>It can help to make websites more dynamic;
<li>It can fix CSS layour issues;
<li>Easy manipulation of DOM elements.
[2]: http://dev.opera.com/articles/view/javascript-uses/
Q: What are those DOM elements?
A: The Document Object Model is a platform interface which enables content, structure and style of documents to be dynamic.
Q: So everyone can use JavaScript?
A: The user must have a browser that supports the use of JavaScript. Almost every
recent browser support this, except for some: Amaya, Dillo, Links, Lynx, Mosaic, NetSurf...
If the browser supports JavaScript, still some issues could prevent the use of JavaScript, e.g.
security measures might ignore the <script> tags.
Q: Is Javascript only used for client-side applications?
A: No, a number of server-side _projects/frameworks_ have been developed
that allow developers to (also) write server-side code in JavaScript. An early example of this
is the Netscape Enterprise Server (released in 1994, soon after the release of JS for browsers).
A more recent example of server-side JavaScript is Node.js, it is currently widely used in real-word
applications.
Q: You mentioned Java, glancing at the name, one can assume they are related.
Is JS perhaps the scripting variant of Java?
A: JavaScript was originally developed under the name Mocha, but was later
officially renamed to LiveScript, then to JavaScript and finally to ECMAScript.
The change to JavaScript had to do with the new support for Java technology (of
SUN Microsystems) in the new Netscape browser version 2.0B3.
This change caused a lot of confusion, but was a slick marketing choice to give
JavaScript the attention it needed.
Q: What other similarities are there between JS and Java other than the confusingly
connected names?
A: There are certainly a couple of characteristics both languages have in common.
Both are Object Oriented Programming languages. Many of their programming structures
are similar. JavaScript has a much smaller and simpler set of commands
than Java.
Both languages also have a C-like syntax. JavaScript's syntax was developed
with Java's syntax in mind.Disregarding these similarities, Java and JavaScript
are very different languages.
Q: What are all these differences then?
A: JavaScript has dynamic and weak typing, whereas Java is statically and strongly typed.
Java programs are compiled to byte-code, while JavaScript is loaded from human-readable source code.
Object in JS are not class-based (as in Java), but prototype-based. JavaScript also has many
functional programming features, that are not present in Java. So besides similiraties in syntax
and standard libraries, Java and JavaScript share very few features. All these differences will be discussed
in more detail later on. (Provide links to relevant questions)
Q: So if Java is not the main inspiration for JS, is it some other language,
or was JS a _completely new language_? (Rephrase last three words)
A: If one ignores the syntax and the object-oriented nature, JS is awfully
similar to functional languages in the Lisp tradition, like for instance
Scheme. As a matter of fact, Brendan Eich, the creator of JavaScript, says that
he was lured by Netscape promising him to make a Scheme for the browser
[2]. A short time before, Brendan Eich had developed in an interest in the
famous [http://mitpress.mit.edu/sicp/][SICP] book, which presents the
tremendous capabilities of a simple functional language, Scheme.
The main influence of Scheme was the presence of first-class functions in
JavaScript. Another similarity with Scheme is the small size of the
language, a handful of built-in types, the single namespace, closures (link to other question (http://jibbering.com/faq/notes/closures/))...
Although JavaScript is an Object Oriented language, Self has influenced javaScript for the use of prototype based inheritance. see [3] for other things to mention.
Q: Prototype based inheritance?
A: In Java, classes represents a collection of object which share the same state space. Objects are manifestations of this class. Objects in a prototype-based language
are clones of prototypes. The reason that ended up in Javascript/ECMA script is basically that 15 years ago, there were much less powerful computers
and much less sophisticated browsers. Choosing the prototype-based method meant the interpreter could be very simple while preserving the desirable properties of object orientation.
[3] https://brendaneich.com/2008/04/popularity/
[4] http://www.crockford.com/javascript/little.html (comparison scheme and JavaScript)
[5] http://http://en.wikipedia.org/wiki/Prototype-based_programming
http://javascript.crockford.com/javascript.html
Q: JS is a scripting language, what does it mean for a language to be a scripting language?
A: A scripting programming language is actually a lightweight language that is mostly
used for writing little programs to execute repetitive tasks. It's a high-level
language that is implemented by an interpreter. Note: JavaScript is not always interpreted.
Some implementations, such as the V8 JavaScript engine, first compile the JavaScript to native machine code.