
JavaScript Programming Concepts Overview
Explore various JavaScript programming concepts including loops, arrays, objects, factorial, methods, functions, constructor, prototypes, and embedding external JavaScript files through informative lecture notes and code examples. Enhance your understanding of JavaScript fundamentals with visual aids and detailed explanations in these slides.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Simple Javascript Example sum = 0; for (i = 1; i < 10; i++) { sum += i*i; } CS 142 Lecture Notes: Javascript Slide 1
Arrays x = new Array(); x[3] = 49; y = ["a , 123, 65]; CS 142 Lecture Notes: Javascript Slide 2
Objects x = new Object(); y = {name: "Alice", age: 23, state: "California"}; x.name = "Bob"; x["age"] = 21; CS 142 Lecture Notes: Javascript Slide 3
Factorial in Javascript function fac(x) { if (x <= 1) { return 1; } return x*fac(x-1); } CS 142 Lecture Notes: Javascript Slide 4
Method Example o = new Object(); o.count = 0; o.increment = function(inc) { if (inc == undefined) { inc = 1; } this.count += inc; return this.count; } CS 142 Lecture Notes: Javascript Slide 5
Functions Can Have Properties function plus1(value) { if (plus1.invocations == undefined) { plus1.invocations = 0; } plus1.invocations++; return value+1; } CS 142 Lecture Notes: Javascript Slide 6
Constructor function Rectangle(width, height) { this.width = width; this.height = height; } r = new Rectangle(26, 14); CS 142 Lecture Notes: Javascript Slide 7
Methods (wrong way) function Rectangle(width, height) { this.width = width; this.height = height; } } this.area = function() { return this.width*this.height; r = new Rectangle(26, 14); a = r.area(); CS 142 Lecture Notes: Javascript Slide 8
Prototypes function Rectangle(width, height) { this.width = width; this.height = height; } Rectangle.prototype.area = function() { return this.width*this.height; } r = new Rectangle(26, 14); a = r.area(); CS 142 Lecture Notes: Javascript Slide 9
Embedding Javascript External Javascript File <body> ... <script type="text/javascript" src="myCode.js" /> <script type="text/javascript"> //<![CDATA[ alert("Page is loading"); //]]> </script> Inline Code <p onclick="alert('Hello, world!');"> Click here.</p> ... </body> Event Handler CS 142 Lecture Notes: Javascript Slide 10
CS 142 Lecture Notes: Cookies Slide 11