JavaScript is a scripting language used to add interactivity to web pages. It allows dynamic updating of HTML content using the Document Object Model. Some key features include first-class functions, prototype-based objects without classes, and the ability to modify objects by adding or removing methods at runtime. JavaScript has many security and correctness issues due to its flexibility and lack of type safety.
JavaScript is a scripting language used to add interactivity to web pages. It allows dynamic updating of HTML content using the Document Object Model. Some key features include first-class functions, prototype-based objects without classes, and the ability to modify objects by adding or removing methods at runtime. JavaScript has many security and correctness issues due to its flexibility and lack of type safety.
JavaScript is the programming language of the web. It can dynamically manipulate HTML content by changing element properties like innerHTML. Functions allow JavaScript code to run in response to events like button clicks or timeouts. JavaScript uses objects and prototypes to define reusable behaviors and properties for objects. It is an important language for web developers to learn alongside HTML and CSS.
JavaScript - An Introduction is a beginner's guide to JavaScript. It starts with very basic level and goes to intermediate level. You'll be introduced with every language constructs, Event handling, Form handling and AJAX which is supported by JavaScript with XMLHttpRequest object. This XHR object is discussed in enough detail so that you can understand how the underlying AJAX functionality works in jQuery. At the end it discusses advance concepts and library build on/around JavaScript.
JavaScript is a scripting language used to make web pages interactive. It was created in 1995 and standardized as ECMAScript. JavaScript can access and modify the content, structure, and style of documents. It is used to handle events, perform animations, and interact with forms on web pages. Common uses of JavaScript include form validation, navigation menus, lightboxes, and sliders on websites.
This document provides an overview of JavaScript, including:
- JavaScript is not related to Java and was originally called LiveScript.
- JavaScript code is run in web browsers by an interpreter built into the browser, not on servers.
- JavaScript can be used to add interactivity to HTML pages by including <script> tags and running code when pages load or in response to user events.
- JavaScript functions and variables can be defined and used to manipulate the DOM and handle user interactions.
The document discusses JavaScript, describing it as:
- Created in 1995 by Netscape and based on the ECMAScript standard.
- A dynamic, weakly typed, object-oriented programming language that is often misunderstood.
- Used for client-side scripting of webpages as well as server-side and application scripting.
- Commonly disliked due to past bad practices, implementations, and browser differences, but these issues are improving over time.
This document provides an overview of JavaScript for students. It defines JavaScript, explains why and how it is used, and covers basic JavaScript concepts like comments, functions, and events. Some key points:
- JavaScript is a scripting language commonly used for web development to make pages dynamic and interactive. It runs in the browser rather than on servers.
- JavaScript can be used to validate forms, change content, hide/show elements, and more. Popular uses include adding interactivity to websites and building front-end frameworks.
- Code is inserted between <script> tags and can be placed in HTML <head> or <body>. Functions are blocks of reusable code defined with function keywords.
- Events
JavaScript is a scripting language originally designed for web browsers but now used everywhere. It has dynamic typing and supports object-oriented, imperative, and functional programming. JavaScript was created in 1995 and standardized in 1999. It is now the most popular language on GitHub. JavaScript can be used to build interactive web pages, desktop applications, server-side applications, IoT applications, and real-time applications. The core data types in JavaScript are Number, String, Boolean, Object, Function, Array, Date, and Regular Expressions. JavaScript supports features like variables, flow control, error handling, debugging, and JSON for data exchange.
Video links: Part 1 : http://www.youtube.com/watch?v=lWSV4JLLJ8E Part2 : http://www.youtube.com/watch?v=-MvSBqPlMdY
This document provides an outline and overview of client-side technologies including JavaScript, DOM, and jQuery. The outline includes sections on JavaScript concepts like data types, control structures, arrays, functions, and objects. It also covers DOM levels and manipulating the DOM, as well as introductions to jQuery for selecting elements, changing styles, and handling events. The presentation provides an overview of these key client-side technologies for students.
This document provides an outline and overview of client-side technologies including JavaScript, DOM, and jQuery. The outline covers JavaScript concepts like data types, control structures, arrays, functions, and objects. It also covers DOM levels and manipulating the DOM. Finally, it discusses jQuery and how to load, select elements, handle events, and more. The presentation aims to familiarize students with these important front-end technologies.
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTAAFREEN SHAIKH
This document provides information about JavaScript including:
- JavaScript is a client-side scripting language used to make web pages dynamic. It was created by Brendan Eich at Netscape.
- There are two types of scripting languages - client-side (JavaScript, VBScript) and server-side (ASP, PHP, Perl). Client-side scripts run on the browser while server-side scripts run on the web server.
- JavaScript has various data types including strings, numbers, Booleans, undefined and null. It also has operators like arithmetic, comparison, logical and assignment operators.
- Functions, objects, and events are important concepts in JavaScript. Functions allow code to be reused, objects bundle data
This document provides an overview and preview of JavaScript concepts that will be covered in 3 parts, including language basics, functions, and inheritance and modules. The first part covers JavaScript types, syntax, objects, arrays, and inheritance. The second part focuses on functions, including defining functions, parameters, scope, closures, and object-oriented patterns. The third part discusses method chaining, augmenting built-in objects, and different inheritance patterns in JavaScript.
This document provides an introduction to JavaScript and its uses for web programming. It explains that JavaScript is a client-side scripting language that allows web pages to become interactive. Some key points covered include:
- JavaScript can change HTML content, styles, validate data, and make calculations.
- Functions are blocks of code that perform tasks when invoked by events or called in code.
- Events like clicks or keyboard presses trigger JavaScript code.
- The DOM (Document Object Model) represents an HTML document that JavaScript can access and modify.
- Forms and user input can be accessed and processed using the DOM.
- Programming flow can be controlled with conditional and loop statements.
-
This afternoon I gave a very short introduction to computer programming at Trade School (tradeschool.ourgoods.org). I used JavaScript to illustrate the process of learning how to program, mainly because there's nothing to install and it has many practical uses.
This document provides an overview of JavaScript, including:
- JavaScript is a prototype-based, dynamic, loosely typed, multi-paradigm scripting language used primarily for client-side web applications.
- JavaScript can also be used for server-side applications with Node.js, databases like MongoDB, and other applications.
- The basics of JavaScript include variables, functions, objects, and operators. Functions have their own scope and arguments are passed by value for primitives and by reference for objects.
- The Document Object Model (DOM) represents HTML documents and allows JavaScript to programmatically access and modify elements and attributes.
- Popular JavaScript libraries like jQuery simplify DOM manipulation and other tasks, using CSS selectors
JavaScript is a client-side scripting language that allows dynamic interactions and effects on web pages. It can be inserted directly into HTML code or linked via external .js files. The DOM (Document Object Model) represents an HTML or XML document as a tree structure, with nodes for elements, attributes, and text. This allows JavaScript to access and manipulate the content, structure, and styling of documents. Common JavaScript objects include String, Date, Array, and Math objects for manipulating text, dates, arrays of values, and mathematical operations respectively.
JavaScript is a client-side scripting language that adds interactivity to HTML pages. It can be embedded in HTML using <script> tags and scripts can be placed internally in the HTML file or externally in a .js file. JavaScript code can be inserted in the <head> or <body> sections, but is typically placed at the end of the <body> for faster page loads. Core JavaScript concepts include variables, objects, functions, operators, conditions, loops, and arrays. The DOM (Document Object Model) allows JavaScript to access and modify HTML elements on the page and events can be used to trigger JavaScript functions in response to user actions.
JavaScript New Tutorial Class XI and XII.pptxrish15r890
The document provides an introduction to JavaScript including:
- JavaScript was developed by Branden Eich in 1995 and is a lightweight, interpreted programming language designed for creating network-centric applications.
- JavaScript is dynamic and commonly used for client-side scripting to interact with users and make dynamic web pages. It has object-oriented capabilities.
- The document discusses JavaScript variables, data types, comments, and keywords as well as uses like client-side validation, manipulating HTML, and presentations.
A SEW-EURODRIVE brake repair kit is needed for maintenance and repair of specific SEW-EURODRIVE brake models, like the BE series. It includes all necessary parts for preventative maintenance and repairs. This ensures proper brake functionality and extends the lifespan of the brake system
More Related Content
Similar to Java Script Programming on Web Application (20)
JavaScript is a scripting language originally designed for web browsers but now used everywhere. It has dynamic typing and supports object-oriented, imperative, and functional programming. JavaScript was created in 1995 and standardized in 1999. It is now the most popular language on GitHub. JavaScript can be used to build interactive web pages, desktop applications, server-side applications, IoT applications, and real-time applications. The core data types in JavaScript are Number, String, Boolean, Object, Function, Array, Date, and Regular Expressions. JavaScript supports features like variables, flow control, error handling, debugging, and JSON for data exchange.
Video links: Part 1 : http://www.youtube.com/watch?v=lWSV4JLLJ8E Part2 : http://www.youtube.com/watch?v=-MvSBqPlMdY
This document provides an outline and overview of client-side technologies including JavaScript, DOM, and jQuery. The outline includes sections on JavaScript concepts like data types, control structures, arrays, functions, and objects. It also covers DOM levels and manipulating the DOM, as well as introductions to jQuery for selecting elements, changing styles, and handling events. The presentation provides an overview of these key client-side technologies for students.
This document provides an outline and overview of client-side technologies including JavaScript, DOM, and jQuery. The outline covers JavaScript concepts like data types, control structures, arrays, functions, and objects. It also covers DOM levels and manipulating the DOM. Finally, it discusses jQuery and how to load, select elements, handle events, and more. The presentation aims to familiarize students with these important front-end technologies.
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTAAFREEN SHAIKH
This document provides information about JavaScript including:
- JavaScript is a client-side scripting language used to make web pages dynamic. It was created by Brendan Eich at Netscape.
- There are two types of scripting languages - client-side (JavaScript, VBScript) and server-side (ASP, PHP, Perl). Client-side scripts run on the browser while server-side scripts run on the web server.
- JavaScript has various data types including strings, numbers, Booleans, undefined and null. It also has operators like arithmetic, comparison, logical and assignment operators.
- Functions, objects, and events are important concepts in JavaScript. Functions allow code to be reused, objects bundle data
This document provides an overview and preview of JavaScript concepts that will be covered in 3 parts, including language basics, functions, and inheritance and modules. The first part covers JavaScript types, syntax, objects, arrays, and inheritance. The second part focuses on functions, including defining functions, parameters, scope, closures, and object-oriented patterns. The third part discusses method chaining, augmenting built-in objects, and different inheritance patterns in JavaScript.
This document provides an introduction to JavaScript and its uses for web programming. It explains that JavaScript is a client-side scripting language that allows web pages to become interactive. Some key points covered include:
- JavaScript can change HTML content, styles, validate data, and make calculations.
- Functions are blocks of code that perform tasks when invoked by events or called in code.
- Events like clicks or keyboard presses trigger JavaScript code.
- The DOM (Document Object Model) represents an HTML document that JavaScript can access and modify.
- Forms and user input can be accessed and processed using the DOM.
- Programming flow can be controlled with conditional and loop statements.
-
This afternoon I gave a very short introduction to computer programming at Trade School (tradeschool.ourgoods.org). I used JavaScript to illustrate the process of learning how to program, mainly because there's nothing to install and it has many practical uses.
This document provides an overview of JavaScript, including:
- JavaScript is a prototype-based, dynamic, loosely typed, multi-paradigm scripting language used primarily for client-side web applications.
- JavaScript can also be used for server-side applications with Node.js, databases like MongoDB, and other applications.
- The basics of JavaScript include variables, functions, objects, and operators. Functions have their own scope and arguments are passed by value for primitives and by reference for objects.
- The Document Object Model (DOM) represents HTML documents and allows JavaScript to programmatically access and modify elements and attributes.
- Popular JavaScript libraries like jQuery simplify DOM manipulation and other tasks, using CSS selectors
JavaScript is a client-side scripting language that allows dynamic interactions and effects on web pages. It can be inserted directly into HTML code or linked via external .js files. The DOM (Document Object Model) represents an HTML or XML document as a tree structure, with nodes for elements, attributes, and text. This allows JavaScript to access and manipulate the content, structure, and styling of documents. Common JavaScript objects include String, Date, Array, and Math objects for manipulating text, dates, arrays of values, and mathematical operations respectively.
JavaScript is a client-side scripting language that adds interactivity to HTML pages. It can be embedded in HTML using <script> tags and scripts can be placed internally in the HTML file or externally in a .js file. JavaScript code can be inserted in the <head> or <body> sections, but is typically placed at the end of the <body> for faster page loads. Core JavaScript concepts include variables, objects, functions, operators, conditions, loops, and arrays. The DOM (Document Object Model) allows JavaScript to access and modify HTML elements on the page and events can be used to trigger JavaScript functions in response to user actions.
JavaScript New Tutorial Class XI and XII.pptxrish15r890
The document provides an introduction to JavaScript including:
- JavaScript was developed by Branden Eich in 1995 and is a lightweight, interpreted programming language designed for creating network-centric applications.
- JavaScript is dynamic and commonly used for client-side scripting to interact with users and make dynamic web pages. It has object-oriented capabilities.
- The document discusses JavaScript variables, data types, comments, and keywords as well as uses like client-side validation, manipulating HTML, and presentations.
A SEW-EURODRIVE brake repair kit is needed for maintenance and repair of specific SEW-EURODRIVE brake models, like the BE series. It includes all necessary parts for preventative maintenance and repairs. This ensures proper brake functionality and extends the lifespan of the brake system
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...sebastianku31
The International Journal of Software Engineering & Applications (IJSEA) is a bi-monthly open access peer-reviewed journal that publishes articles which contribute new results in all areas of the Software Engineering & Applications. The goal of this journal is to bring together researchers and practitioners from academia and industry to focus on understanding Modern software engineering concepts & establishing new collaborations in these areas.
May 2025: Top 10 Read Articles Advanced Information Technologyijait
International journal of advanced Information technology (IJAIT) is a bi monthly open access peer-reviewed journal, will act as a major forum for the presentation of innovative ideas, approaches, developments, and research projects in the area advanced information technology applications and services. It will also serve to facilitate the exchange of information between researchers and industry professionals to discuss the latest issues and advancement in the area of advanced IT. Core areas of advanced IT and multi-disciplinary and its applications will be covered during the conferences.
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...gerogepatton
The International Journal of Artificial Intelligence & Applications (IJAIA) is a bi monthly open access peer-reviewed journal that publishes articles which contribute new results in all areas of the Artificial Intelligence & Applications (IJAIA). It is an international journal intended for professionals and researchers in all fields of AI for researchers, programmers, and software and hardware manufacturers. The journal also aims to publish new attempts in the form of special issues on emerging areas in Artificial Intelligence and applications.
Electrical and Electronics Engineering: An International Journal (ELELIJ)elelijjournal653
Call For Papers...!!!
Electrical and Electronics Engineering: An International Journal (ELELIJ)
Web page link: https://wireilla.com/engg/eeeij/index.html
Submission Deadline: June 08, 2025
Submission link: [email protected]
Contact Us: [email protected]
The development of smart cities holds immense significance in shaping a nation's urban fabric and effectively addressing urban challenges that profoundly impact the economy. Among these challenges, road accidents pose a significant obstacle to urban progress, affecting lives, supply chain efficiency, and socioeconomic well-being. To address this issue effectively, accurate forecasting of road accidents is crucial for policy formulation and enhancing safety measures. Time series forecasting of road accidents provides invaluable insights for devising strategies, enabling swift actions in the short term to reduce accident rates, and informing well-informed road design and safety management policies for the long term, including the implementation of flyovers, and the enhancement of road quality to withstand all weather conditions. Deep Learning's exceptional pattern recognition capabilities have made it a favored approach for accident forecasting. The study comprehensively evaluates deep learning models, such as RNN, LSTM, CNN+LSTM, GRU, Transformer, and MLP, using a ten-year dataset from the esteemed Smart Road Accident Database in Hubballi-Dharwad. The findings unequivocally underscore LSTM's superiority, exhibiting lower errors in both yearly (RMSE: 0.291, MAE: 0.271, MAPE: 6.674%) and monthly (RMSE: 0.186, MAE: 0.176, MAPE: 5.850%) variations. Based on these compelling findings, the study provides strategic recommendations to urban development authorities, emphasizing comprehensive policy frameworks encompassing short-term and long-term measures to reduce accident rates alongside meticulous safety measures and infrastructure planning. By leveraging insights from deep learning models, urban development authorities can adeptly shape the urban landscape, fostering safer environments and contributing to global safety and prosperity.
Call For Papers - International Journal on Natural Language Computing (IJNLC)kevig
Natural Language Processing is a programmed approach to analyze text that is based on both a
set of theories and a set of technologies. This forum aims to bring together researchers who have
designed and build software that will analyze, understand, and generate languages that humans use
naturally to address computers.
2. slide 2
What’s a Scripting Language?
Language used to write programs that compute
inputs to another language processor
• One language embedded in another
– Embedded JavaScript computes HTML input to the browser
– Shell scripts compute commands executed by the shell
Common characteristics of scripting languages
• String processing – since commands often strings
• Simple program structure, define things “on the fly”
• Flexibility preferred over efficiency, safety
– Is lack of safety a good thing? (Example: JavaScript used for
Web applications…)
3. slide 3
Why JavaScript?
“Active” web pages
Web 2.0
• AJAX, huge number of Web-based applications
Some interesting and unusual features
• First-class functions - interesting
• Objects without classes - slightly unusual
• Powerful modification capabilities - very unusual
– Add new method to object, redefine prototype, …
Many security and correctness issues
“The world’s most misunderstood prog.
language”
4. slide 4
JavaScript History
Developed by Brendan Eich at Netscape
• Scripting language for Navigator 2
Later standardized for browser compatibility
• ECMAScript Edition 3 (aka JavaScript 1.5)
Related to Java in name only
• “JavaScript is to Java as carpet is to car”
• Name was part of a marketing deal
Various implementations available
• SpiderMonkey C implementation (from Mozilla)
• Rhino Java implementation (also from Mozilla)
5. slide 5
Motivation for JavaScript
Netscape, 1995
• > 90% browser market share
– “I hacked the JS prototype in ~1 week in May and it showed!
Mistakes were frozen early. Rest of year spent embedding in
browser” -- Brendan Eich, ICFP talk, 2006
Design goals
• Make it easy to copy/paste snippets of code
• Tolerate “minor” errors (missing semicolons)
• Simplified onclick, onmousedown, etc., event handling
• Pick a few hard-working, powerful primitives
– First-class functions, objects everywhere, prototype-based
• Leave all else out!
6. slide 6
Common Uses of JavaScript
Form validation
Page embellishments and special effects
Navigation systems
Basic math calculations
Dynamic content manipulation
Sample applications
• Dashboard widgets in Mac OS X, Google Maps,
Philips universal remotes, Writely word processor,
hundreds of others…
7. slide 7
Example 1: Add Two Numbers
<html>
…
<p> … </p>
<script>
var num1, num2, sum
num1 = prompt("Enter first number")
num2 = prompt("Enter second number")
sum = parseInt(num1) + parseInt(num2)
alert("Sum = " + sum)
</script>
…
</html>
8. slide 8
Example 2: Browser Events
<script type="text/JavaScript">
function whichButton(event) {
if (event.button==1) {
alert("You clicked the left mouse button!") }
else {
alert("You clicked the right mouse button!")
}}
</script>
…
<body onmousedown="whichButton(event)">
…
</body>
Mouse event causes
page-defined
function to be called
Other events: onLoad, onMouseMove, onKeyPress, onUnLoad
9. slide 9
Example 3: Page Manipulation
Some possibilities
• createElement(elementName)
• createTextNode(text)
• appendChild(newChild)
• removeChild(node)
Example: add a new list item
var list = document.getElementById('t1')
var newitem = document.createElement('li')
var newtext = document.createTextNode(text)
list.appendChild(newitem)
newitem.appendChild(newtext)
This uses the browser
Document Object Model
(DOM). We will focus on
JavaScript as a language,
not its use in the
browser
10. Document Object Model (DOM)
HTML page is structured data
DOM provides representation of this hierarchy
Examples
• Properties: document.alinkColor, document.URL,
document.forms[ ], document.links[ ],
document.anchors[ ], …
• Methods: document.write(document.referrer)
– These change the content of the page!
Also Browser Object Model (BOM)
• Window, Document, Frames[], History, Location,
Navigator (type and version of browser)
slide 10
12. slide 12
Reading Properties with
JavaScript
Sample script
• Example 1 returns "ul"
• Example 2 returns "null"
• Example 3 returns "li"
• Example 4 returns "text"
– A text node below the "li" which holds the actual text data as its value
• Example 5 returns " Item 1 "
1. document.getElementById('t1').nodeName
2. document.getElementById('t1').nodeValue
3. document.getElementById('t1').firstChild.nodeName
4. document.getElementById('t1').firstChild.firstChild.nodeName
5. document.getElementById('t1').firstChild.firstChild.nodeValue
<ul id="t1">
<li> Item 1 </li>
</ul>
Sample HTML
13. slide 13
Language Basics
JavaScript is case sensitive
• onClick, ONCLICK, … are HTML, thus not case-sensitive
Statements terminated by returns or semi-colons
• x = x+1; same as x = x+1
“Blocks” of statements enclosed in { …}
Variables
• Define using the var statement
• Define implicitly by its first use, which must be an
assignment
– Implicit defn has global scope, even if occurs in nested scope!
14. slide 14
JavaScript Blocks
Use { } for grouping; not a separate scope
js> var x=3;
js> x
3
js> {var x=4; x}
4
js> x
4
Not blocks in the sense of other languages
15. slide 15
JavaScript Primitive Datatypes
Boolean: true and false
Number: 64-bit floating point
• Similar to Java double and Double
• No integer type
• Special values NaN (not a number) and Infinity
String: sequence of zero or more Unicode
chars
• No separate character type (just strings of length 1)
• Literal strings using ' or " characters (must match)
Special objects: null and undefined
16. slide 16
Objects
An object is a collection of named properties
Think of it as an associative array or hash table
• Set of name:value pairs
– objBob = {name: “Bob", grade: 'A', level: 3};
• Play a role similar to lists in Lisp / Scheme
New members can be added at any time
– objBob.fullname = 'Robert';
Can have methods
Can refer to this
17. slide 17
Functions
Functions are objects with method called “( )”
• A property of an object may be a function (=method)
– function max(x,y) { if (x>y) return x; else return y;};
– max.description = “return the maximum of two arguments”;
• Local declarations may appear in function body
Call can supply any number of arguments
• functionname.length : # of arguments in definition
• functionname.arguments.length : # arguments in call
• Basic types are passed by value, objects by reference
“Anonymous” functions
• (function (x,y) {return x+y}) (2,3);
18. slide 18
Examples of Functions
Curried functions
– function CurriedAdd(x) { return function(y){ return x+y} };
– g = CurriedAdd(2);
– g(3)
Variable number of arguments
– function sumAll() {
var total=0;
for (var i=0; i< sumAll.arguments.length; i++)
total+=sumAll.arguments[i];
return(total); }
– sumAll(3,5,3,5,3,2,6)
19. slide 19
Anonymous Functions
Anonymous functions very useful for callbacks
• setTimeout(function() { alert("done"); }, 10000)
• Evaluation of alert("done") delayed until function call
Simulate blocks by function definition and call
• var u = { a:1, b:2 }
• var v = { a:3, b:4 }
• (function (x,y) {
var tempA = x.a; var tempB =x.b; // local variables
x.a=y.a; x.b=y.b;
y.a=tempA; y.b=tempB
}) (u,v) // Works because objs are passed by ref
20. slide 20
Basic Object Features
Use a function to construct an object
• function car(make, model, year) {
this.make = make;
this.model = model;
this.year = year; }
Objects have prototypes, can be changed
• var c = new car(“Ford”,”Taurus”,1988);
• car.prototype.print = function () {
return this.year + “ “ + this.make + “ “ + this.model;}
• c.print();
21. slide 21
JavaScript in Web Pages
Embedded in HTML page as <script> element
• JavaScript written directly inside <script> element
– <script> alert("Hello World!") </script>
• Linked file as src attribute of the <script> element
<script type="text/JavaScript" src=“functions.js"></script>
Event handler attribute
<a href="http://www.yahoo.com "
onmouseover="alert('hi');">
Pseudo-URL referenced by a link
<a href=“JavaScript: alert(‘You clicked’);”>Click me</a>
We are looking at JavaScript as a language; ignore BOM, DOM, AJAX
22. slide 22
Language Features in This
Class
Stack memory management
• Parameters, local variables in activation records
Garbage collection
Closures
• Function together with environment (global variables)
Exceptions
Object features
• Dynamic lookup, encapsulation, subtyping,
inheritance
Concurrency
23. slide 23
Stack Memory Management
Local variables in activation record of function
function f(x) {
var y = 3;
function g(z) { return y+z;};
return g(x);
}
var x= 1; var y =2;
f(x) + y;
24. slide 24
Garbage Collection
Automatic reclamation of unused memory
Navigator 2: per-page memory management
• Reclaim memory when browser changes page
Navigator 3: reference counting
• Each memory region has associated count
• Count modified when pointers are changed
• Reclaim memory when count reaches zero
Navigator 4: mark-and-sweep, or equivalent
• Garbage collector marks reachable memory
• Sweep and reclaim unreachable memory
25. slide 25
Closures
Return a function from function call
• function f(x) {
var y = x;
return function (z){y += z; return y;}
}
• var h = f(5);
• h(3);
Can use this idea to define objects with
“private” fields (subtle)
• See
http://www.crockford.com/JavaScript/private.html
26. slide 26
Exceptions
Throw an expression of any type
throw "Error2";
throw 42;
throw {toString: function() { return "I'm an object!"; } };
Catch
try {
} catch (e if e == “FirstException") { // do something
} catch (e if e == “SecondException") { // do something else
} catch (e){ // executed if no match above
}
Reference: http://developer.mozilla.org/en/docs/
Core_JavaScript_1.5_Guide :Exception_Handling_Statements
27. slide 27
Object features
Dynamic lookup
• Method depends on run-time value of object
Encapsulation
• Object contains private data, public operations
Subtyping
• Object of one type can be used in place of another
Inheritance
• Use implementation of one kind of object to
implement another kind of object
28. slide 28
Concurrency
JavaScript itself is single-threaded
• How can we tell if a language provides concurrency?
AJAX provides a form of concurrency
• Create XMLHttpRequest object, set callback function
• Call request method, which continues asynchronously
• Reply from remote site executes callback function
– Event waits in event queue…
• Closures important for proper execution of callbacks
Another form of concurrency
• Use SetTimeout to do cooperative multi-tasking
29. slide 29
JavaScript eval
Evaluate string as code (seen this before?)
• The eval function evaluates a string of JavaScript code,
in scope of the calling code
– var code = "var a = 1";
– eval(code); // a is now '1‘
– var obj = new Object();
– obj.eval(code); // obj.a is now 1
• Common use: efficiently deserialize a complicated data
structure received over network via XMLHttpRequest
What does it cost to have eval in the language?
• Can you do this in C? What would it take to implement?
30. slide 30
Unusual Features of JavaScript
Eval, run-time type checking functions
Support for pattern matching (reg.
expressions)
Can add methods to an object
Can delete methods of an object
• myobj.a = 5; myobj.b = 12; delete myobj.a;
Iterate over methods of an object
• for (variable in object) { statements }
With statement (“considered harmful” – why?)
• with (object) { statements }