<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=WebFund_2024F_Lecture_9</id>
	<title>WebFund 2024F Lecture 9 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=WebFund_2024F_Lecture_9"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2024F_Lecture_9&amp;action=history"/>
	<updated>2026-04-22T11:31:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2024F_Lecture_9&amp;diff=24784&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture for October 8, 2024 is now available: * [https://homeostasis.scs.carleton.ca/~soma/webfund-2024f/lectures/comp2406-2024f-lec09-20241008.m4v video] * [https://homeostasis.scs.carleton.ca/~soma/webfund-2024f/lectures/comp2406-2024f-lec09-20241008.cc.vtt auto-generated captions]  ==Notes==  &lt;pre&gt; Lecture 9 ---------  I&#039;m happy to answer any questions, but otherwise will be moving on to new material.  If you want to work on your code locally...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2024F_Lecture_9&amp;diff=24784&amp;oldid=prev"/>
		<updated>2024-10-08T19:48:01Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture for October 8, 2024 is now available: * [https://homeostasis.scs.carleton.ca/~soma/webfund-2024f/lectures/comp2406-2024f-lec09-20241008.m4v video] * [https://homeostasis.scs.carleton.ca/~soma/webfund-2024f/lectures/comp2406-2024f-lec09-20241008.cc.vtt auto-generated captions]  ==Notes==  &amp;lt;pre&amp;gt; Lecture 9 ---------  I&amp;#039;m happy to answer any questions, but otherwise will be moving on to new material.  If you want to work on your code locally...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture for October 8, 2024 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/webfund-2024f/lectures/comp2406-2024f-lec09-20241008.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/webfund-2024f/lectures/comp2406-2024f-lec09-20241008.cc.vtt auto-generated captions]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 9&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m happy to answer any questions, but otherwise will be moving on to new material.&lt;br /&gt;
&lt;br /&gt;
If you want to work on your code locally but run it in the class VM, using something like git makes sense, specifically with the master repository being on github.&lt;br /&gt;
 - you push updates from your local machine and then pull down updates on the VM&lt;br /&gt;
 - classic way of doing cloud development&lt;br /&gt;
 - but there&amp;#039;s a learning curve, outside the scope of this class&lt;br /&gt;
&lt;br /&gt;
My expectation is that you will understand the code in the assignments on a line-by-line level.&lt;br /&gt;
 - know why each line is there, consequences of removing or altering any of them&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Remember that at some point we&amp;#039;ll start doing interviews...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Main topic today: client-side JavaScript&lt;br /&gt;
 - what we&amp;#039;re going to be focusing on in one way or another for the rest of the semester.&lt;br /&gt;
&lt;br /&gt;
let vs var&lt;br /&gt;
 - both used to declare variables&lt;br /&gt;
 - var is function scope, let is block scope&lt;br /&gt;
&lt;br /&gt;
For me, let isn&amp;#039;t so useful because I like my functions to not be too long, so there aren&amp;#039;t too many variables that are declared and used in it.&lt;br /&gt;
&lt;br /&gt;
If you have larger functions, then let can be useful.&lt;br /&gt;
&lt;br /&gt;
Many people don&amp;#039;t like var so much because it is &amp;quot;hoisted&amp;quot; up, i.e., declarations late in the function act as if they were declared at the top.&lt;br /&gt;
 - but this makes sense to me since this is how C works&lt;br /&gt;
&lt;br /&gt;
let has block-level scope so it is &amp;quot;safer&amp;quot; in the sense of smaller scope, but that doesn&amp;#039;t seem to matter much in practice&lt;br /&gt;
&lt;br /&gt;
Common use case for let&lt;br /&gt;
 - declare variables inside the scope of an if/else statement&lt;br /&gt;
 - here this is good if you don&amp;#039;t want variables to be visible outside of the if or else clause&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Demo of scoping rules&lt;br /&gt;
&lt;br /&gt;
function outer(a) {&lt;br /&gt;
&lt;br /&gt;
    function inner(b) {&lt;br /&gt;
	if (b &amp;gt; 7) {&lt;br /&gt;
	    let x = 5;&lt;br /&gt;
	    // var x = 5;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
        return a + b + x;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return inner(x);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
var x = 12;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you&amp;#039;re declaring a variable to have the scope of a block, use let. Otherwise, use var or let.&lt;br /&gt;
&lt;br /&gt;
Question: does JavaScript do shallow or deep copies of arrays and objects?&lt;br /&gt;
&lt;br /&gt;
Answer: shallow only, on assignment&lt;br /&gt;
&lt;br /&gt;
a = [1,2,3];&lt;br /&gt;
&lt;br /&gt;
b = a;&lt;br /&gt;
&lt;br /&gt;
a and b both refer to the same array.&lt;br /&gt;
 - so changes to b will be reflected in a&lt;br /&gt;
 - declaring const makes no difference (objects &amp;amp; arrays are always mutable)&lt;br /&gt;
 - strings are mostly immutable however&lt;br /&gt;
 - really, a and b are pointers to the array&lt;br /&gt;
    - and if they were declared const, then they are immutable pointers&lt;br /&gt;
&lt;br /&gt;
How to clone an array:&lt;br /&gt;
&lt;br /&gt;
  https://www.geeksforgeeks.org/how-to-clone-an-array-in-javascript/&lt;br /&gt;
&lt;br /&gt;
Interestingly enough, the slice operator creates a copy of the array or string always&lt;br /&gt;
 - so you can use it as a copy method&lt;br /&gt;
 - but the copy will just be one level, won&amp;#039;t be recursive&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s talk about client-side JavaScript&lt;br /&gt;
&lt;br /&gt;
The origin of JavaScript was in the web browser, not the web server&lt;br /&gt;
 - it was a language that was to be embedded inside of a web page&lt;br /&gt;
 - specifically, you&amp;#039;d have an HTML &amp;lt;script&amp;gt; tags which would enclose JavaScript code.&lt;br /&gt;
   - or, you could load JavaScript from a separate file, but same syntax&lt;br /&gt;
&lt;br /&gt;
Why run JavaScript (or any language) inside of a web page?&lt;br /&gt;
 - originally the idea was very modest&lt;br /&gt;
 - do things like validate form data, implement drop-down menus,&lt;br /&gt;
   just make the page slightly interactive&lt;br /&gt;
&lt;br /&gt;
And in fact client-side JavaScript had lots of limitations&lt;br /&gt;
 - would only run when the page was loaded or when specific user actions happened (i.e., when a user pressed a button)&lt;br /&gt;
 - HEAVILY sandboxed for security&lt;br /&gt;
    - no local file access, or local access at all&lt;br /&gt;
    - no persistent storage in browser&lt;br /&gt;
    - very limited network access (same origin policy)&lt;br /&gt;
 &lt;br /&gt;
So, JavaScript code couldn&amp;#039;t run for very long and couldn&amp;#039;t access much. This kept JavaScript secure.&lt;br /&gt;
&lt;br /&gt;
But then web developers wanted to do more and more&lt;br /&gt;
 - they wanted to make web apps, not web documents&lt;br /&gt;
&lt;br /&gt;
But one little addition to JavaScript changed the game: XMLHttpRequest&lt;br /&gt;
 - this allowed for background network queries and for background JavaScript code execution&lt;br /&gt;
 - originally implemented using an ActiveX control, but then became built-in to all modern web browsers&lt;br /&gt;
&lt;br /&gt;
ActiveX controls were digitally signed bits of Windows code that could be downloaded and executed by Microsoft&amp;#039;s Internet Explorer web browser&lt;br /&gt;
 - yes, it was downloading binaries from the Internet that could do anything&lt;br /&gt;
 - all that protected you was the fact that they came from &amp;quot;authorized&amp;quot; entities&lt;br /&gt;
 - there were evil ActiveX controls, and now nobody supports them anymore&lt;br /&gt;
   because they were a BAD IDEA&lt;br /&gt;
&lt;br /&gt;
Microsoft created XMLHttpRequest for Outlook Web Access&lt;br /&gt;
 - because the Outlook team knew they couldn&amp;#039;t make a good web email&lt;br /&gt;
   client without background network access and background code execution&lt;br /&gt;
&lt;br /&gt;
But this opened the door for web apps that have taken over from desktop apps&lt;br /&gt;
&lt;br /&gt;
The big ones that showed people what was possible were Gmail &amp;amp; Google Maps&lt;br /&gt;
&lt;br /&gt;
Document Object Model (DOM)&lt;br /&gt;
 - the key technology bridging the world of JavaScript and HTML&lt;br /&gt;
 - you COULD have JavaScript manipulate HTML as a big string, but that is not efficient and is very error prone&lt;br /&gt;
 - instead, the browser converts HTML into a bunch of JavaScript objects&lt;br /&gt;
   that can be queried and manipulated&lt;br /&gt;
    - when those objects are changed, what the user sees changes as well&lt;br /&gt;
&lt;br /&gt;
The DOM is the killer app of client-side JavaScript&lt;br /&gt;
 - no other client-side language has direct access to the DOM, they all&lt;br /&gt;
   go through JavaScript&lt;br /&gt;
   (one day WebAssembly may have access but not today)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>