5. danielfisher.com
Introduction
• Developed by Brendan Eich
at Netscape in 1994.
– A lightweight interpreted
language
– Considered client-server
solution as a distributed OS
– Complement Java by
appealing to nonprofessional
programmers
• Like Microsoft's VB.
6. danielfisher.com
The Language
• JavaScript is a prototype-based scripting
language that is:
– Dynamic
– Weakly typed
– And has first-class functions.
• It is a multi-paradigm language, supporting multiple
programming styles:
– Object-oriented
– Imperative
– Functional
7. danielfisher.com
Adoption by Microsoft
• Internet Explorer 3.0 introduced JavaScript in
1996.
• Internet Information Server 3.0, introduced
support for server-side JavaScript in 1996.
– Microsoft's JavaScript implementation was later
renamed JScript to avoid trademark issues.
– JScript added new date methods to fix the Y2K-
problematic methods in JavaScript, which were
based on Java's java.util.Date class.
8. danielfisher.com
Server side JavaScript
• Netscape introduced an implementation of
the language for server-side scripting with
Netscape Enterprise Server in 1995.
– Since the mid-2000s, there has been a
proliferation of server-side JavaScript
implementations.
• node.js (2009)is one recent notable example of
server-side JavaScript being used in real-world
applications.
9. danielfisher.com
Standardization
• In November 1996, Netscape announced that
it had submitted JavaScript to Ecma
International for consideration as an industry
standard
– Subsequent work resulted in the standardized
version named ECMAScript.
20. danielfisher.com
String
var y = "Hello World";
var len = y.length.toString();
var part = y.substring(0, 2);
var char = y.charAt(0);
var upper = y.toUpperCase();
var lower = y.toLowerCase();
22. danielfisher.com
Date
var today = new Date();
// sets to current date & time
newYear = new Date(2002, 0, 1);
newYear.getYear()
newYear.getMonth()
newYear.getDay()
newYear.getHours()
newYear.getMinutes()
newYear.getSeconds()
newYear.getMilliseconds()
23. danielfisher.com
The Document object
• Represents the currently loaded document
Attributes of the current document are:
– Title
– Referrer
– URL
– Images
– Forms
– Links
– Colors
23
24. danielfisher.com
Document Methods
• The documents methods include:
document.write()
Like a print statement – the output goes into the
HTML document.
document.writeln()
Adds a newline after printing.
document.write(
"My title is " + document.title
); 24
25. danielfisher.com
The Navigator Object
• Represents the browser. Read-only!
• Attributes include:
– appName
– appVersion
– platform
EIW: Javascript the Language 25
31. danielfisher.com
Javascript Functions
• The keyword function is used to define a
function (subroutine):
function add(x, y) {
return (x + y);
}
• No type is specified for arguments!
31
32. danielfisher.com
Functional Programming
function filter(pred, arr) {
var len = arr.length;
var filtered = [];
for(var i = 0; i < len; i++) {
var val = arr[i];
if(pred(val)) {
filtered.push(val);
}
}
return filtered;
}
var numbersGreaterThan100 =
filter(
function(x) { return (x > 100) ? true : false; },
[12, 200, 42, 11]
);
alert(numbersGreaterThan100);
33. danielfisher.com
BOOK DANIELFISHER.COM
READ LENNYBACON.COM
FOLLOW @LENNYBACON
LINK LINKEDIN.COM/IN/LENNYBACON
XING XING.COM/PROFILE/DANIEL_FISHER
FRIEND FB.COM/DANIEL.FISHER.LENNYBACON
MAIL DANIEL.FISHER@LENNYBACON.COM
SKYPE LENNYBACON
CALL +49 (176) 6159 8612