Latest / CyberSecurity Summary / Quick JavaScript (Quick Programming)
Transcript
- 0:00Speaker 1: Welcome to the deep dive where your curiosity fuels are exploration.
- 0:04Speaker 1: You send us the sources and we distill them down
- 0:07Speaker 1: to the essential insights, saving you time and expanding your knowledge.
- 0:11Speaker 2: It's a great concept.
- 0:12Speaker 1: Today we're tackling a programmer's Quick Start Guide to Web
- 0:15Speaker 1: Development Quick JavaScript by David Metusek. Our mission, driven by
- 0:20Speaker 1: your need for efficient learning, is really to extract the
- 0:24Speaker 1: core concepts of JavaScript and the HTML dom that experienced
- 0:28Speaker 1: coders can grasp rapidly and thoroughly.
- 0:31Speaker 2: And we're using excerpt straight from the book itself exactly.
- 0:33Speaker 1: We'll be drawing straight from the book honestly. The idea
- 0:36Speaker 1: of making this corner stone of webin or activity more accessible,
- 0:40Speaker 1: that's well, that's what gets me going.
- 0:42Speaker 2: Indeed, and what's interesting right off the bat is who
- 0:45Speaker 2: this book isn't for. Yeah, Metusk explicitly advises programming beginners
- 0:50Speaker 2: to start with Python. That tells us a lot. It's
- 0:53Speaker 2: laser focused on bringing established developers up to speed with
- 0:56Speaker 2: JavaScript quickly. It assumes you already have a foundation in
- 0:59Speaker 2: promming principles exactly.
- 1:01Speaker 1: It assumes you know what a loop is, what a
- 1:04Speaker 1: variable is, and it's not trying to be the definitive
- 1:07Speaker 1: JavaScript Bible.
- 1:08Speaker 2: Right, No, not at all. Matustik himself points readers looking
- 1:11Speaker 2: for that really comprehensive reference towards Slannigan's JavaScript the Definitive
- 1:17Speaker 2: Guide a classic, right, So quick JavaScript is about getting
- 1:21Speaker 2: you hands on providing that crucial initial understanding of how
- 1:25Speaker 2: JavaScript talks to and manipulates web pages through the document
- 1:29Speaker 2: object model, the DOM. It's a targeted on ramp, and it's.
- 1:33Speaker 1: A necessary on ramp because well, JavaScript holds this unique position,
- 1:37Speaker 1: doesn't it.
- 1:37Speaker 2: It really does. It's the only language that web browsers
- 1:40Speaker 2: understand natively.
- 1:41Speaker 1: You can think about that for a second.
- 1:43Speaker 2: Yeah, it's ubiquity, isn't accidental. I mean sure, other languages
- 1:47Speaker 2: like Coffee, script or dark can be used for web development,
- 1:49Speaker 2: but they all need a translation step, a compilation into
- 1:52Speaker 2: JavaScript before a browser can actually execute them.
- 1:55Speaker 1: So JavaScript is fundamental. It's the base layer for client
- 1:58Speaker 1: side interactivity. Okay, so JavaScript is the lingua franca of
- 2:02Speaker 1: the browser. Now Metusk brings up something called strict mode
- 2:05Speaker 1: pretty early on. What's the essential insight there? What's the gist?
- 2:10Speaker 2: Think of you strict that exact string as like a
- 2:15Speaker 2: safety switch for your JavaScript code. It was introduced in
- 2:18Speaker 2: ekmascript twenty fifteen six. Okay, by putting that phrase at
- 2:22Speaker 2: the beginning of your script or maybe inside of function,
- 2:25Speaker 2: you're telling the JavaScript engine to enforce a stricter set
- 2:28Speaker 2: of rules. It basically eliminates some potentially problematic or error
- 2:33Speaker 2: prone parts of the language.
- 2:34Speaker 1: Ah, cleaning up some historical baggage sort of.
- 2:36Speaker 2: Yeah, METUSAC emphasizes that for all new JavaScript projects, using
- 2:41Speaker 2: strict mode isn't just a good idea, it's really the
- 2:43Speaker 2: recommended standard. Yeah, so for modern JavaScript you strict is
- 2:47Speaker 2: less of an option and more of a safety net.
- 2:48Speaker 2: You should just always deploy.
- 2:50Speaker 1: That makes sense a way to build more robust code
- 2:52Speaker 1: right from the start. Okay, let's get down to the bedrock,
- 2:54Speaker 1: the core language fundamentals. Where does Matusek begin. Assuming we're
- 2:59Speaker 1: coming from other language like Java or C plus plus.
- 3:01Speaker 2: All, he starts with the absolute essentials. And yeah, if
- 3:05Speaker 2: you're familiar with those languages, you'll find some immediate parallels
- 3:08Speaker 2: for supperate comments. Okay, single line comments using and multiline
- 3:12Speaker 2: comments enclosed in a selgy. Pretty standard stuff across the
- 3:16Speaker 2: programming landscape.
- 3:17Speaker 1: Right, no surprises there for experienced hods. What about the
- 3:21Speaker 1: fundamental types of data we'll be working with in JavaScript,
- 3:24Speaker 1: any quirks.
- 3:25Speaker 2: Well. JavaScript has eight primitive data types. One initial thing
- 3:29Speaker 2: to note, which can be a bit of a surprise,
- 3:32Speaker 2: is that all numbers, whether they look like integers or decimals,
- 3:36Speaker 2: are internally treated as double precision floating point numbers.
- 3:40Speaker 1: Ah okay, so no true integers under the hood unless
- 3:44Speaker 1: you use bigant.
- 3:44Speaker 2: Later exactly, except for bigot, which is newer.
- 3:47Speaker 1: Yeah.
- 3:47Speaker 2: And another interesting historical tidbit, a real quirk applying the
- 3:51Speaker 2: type of operator to noll actually returns the string object.
- 3:55Speaker 1: Uh huh, that's weird.
- 3:57Speaker 2: It is. It's a well known design flaw from the
- 3:58Speaker 2: language's early days. It's inconsistent, but it's just something you
- 4:02Speaker 2: have to be aware of, a historical hiccup.
- 4:03Speaker 1: We just have to live with, got it. What else
- 4:06Speaker 1: in the realm of data types?
- 4:07Speaker 2: So beyond those basic primitives, we have user defined objects.
- 4:11Speaker 2: Think of these as collections of named values or properties.
- 4:15Speaker 2: You define them using curly braces with key value.
- 4:18Speaker 1: Pairs, like dictionaries or maps and other languages.
- 4:21Speaker 2: Pretty much. Yeah, yeah, key is the property name, value
- 4:24Speaker 2: is the value. You access these values, usually with dot
- 4:26Speaker 2: notation object dot property name, which is very common, right,
- 4:30Speaker 2: Or you can use bracket notation object property name. That's
- 4:33Speaker 2: handy when the property name is dynamic like stored in
- 4:35Speaker 2: a variable, or maybe contains characters not allowed in dot notation.
- 4:39Speaker 1: Okay, and then provides some built in object types for
- 4:44Speaker 1: common data structures I assume exactly.
- 4:46Speaker 2: Yeah, JavaScript comes equipped with several built in object types.
- 4:50Speaker 2: You've got a raise for ordered lists, sets for collections
- 4:53Speaker 2: of unique items, maps for key value pairs, where keys
- 4:56Speaker 2: can be anything.
- 4:57Speaker 1: More flexible keys than plain objects.
- 4:59Speaker 2: Right. Keys can be any type in maps, And of
- 5:02Speaker 2: course there are building types for dates and regular expressions too.
- 5:05Speaker 2: Let's maybe focus on a few key ones first, like arrays.
- 5:08Speaker 1: Sure, how do we make arrays?
- 5:10Speaker 2: Usually with square brackets with comma separated values inside there's
- 5:13Speaker 2: zero indexed like in many languages, and you can even
- 5:17Speaker 2: nest them to create multidimensional arrays.
- 5:19Speaker 1: Okay.
- 5:20Speaker 2: Now there's an older array constructor, but Modissek advises against
- 5:23Speaker 2: using it. It has this peculiar behavior. If you pass
- 5:27Speaker 2: just a single number, oh yeah, instead of treating an
- 5:29Speaker 2: array with that number in it, it creates an empty
- 5:32Speaker 2: array with that specified length. So called sparse array can
- 5:35Speaker 2: lead to some unexpected results down the line.
- 5:37Speaker 1: Sparse arrays sounds like a potential gotcha, So what's the
- 5:40Speaker 1: better way?
- 5:41Speaker 2: He recommends just using the array literals for direct initialization,
- 5:45Speaker 2: and also array.
- 5:46Speaker 1: Dot from array dot from.
- 5:48Speaker 2: Yeah, it's a static method, really powerful. You can convert
- 5:51Speaker 2: iterable objects like set, strings, even maps into proper arrays.
- 5:54Speaker 2: It's also a neat way to create a shallow copy
- 5:57Speaker 2: of an existing array. Okay, handy, And one key takeaway
- 6:00Speaker 2: about JavaScript arrays is their flexibility. They can hold a
- 6:02Speaker 2: mix of different data types. You can have numbers, strings,
- 6:05Speaker 2: objects all in the same array.
- 6:07Speaker 1: That dynamic nature is a recurring theme with JavaScript, isn't it.
- 6:11Speaker 1: What about sets? How are they useful?
- 6:13Speaker 2: Sets are all about uniqueness their collections of values where
- 6:16Speaker 2: each value can only appear once. Okay, and the order
- 6:19Speaker 2: of elements isn't guaranteed. You create them using you set,
- 6:21Speaker 2: often initializing them with an iterable like another array.
- 6:24Speaker 1: In common operations.
- 6:26Speaker 2: Key operations you'll use are has value to quickly check
- 6:30Speaker 2: if a value exists, add value to insert a new
- 6:33Speaker 2: value if it's already there, nothing happens, which is.
- 6:36Speaker 1: The point, maintains uniqueness exactly.
- 6:38Speaker 2: And delete value to remove a value. Delete actually returns
- 6:42Speaker 2: true if the value is found and removed false otherwise.
- 6:45Speaker 1: Unique unordered collections useful for things like removing duplicates quickly. Now,
- 6:50Speaker 1: regular expressions always a bit tricky. What's the initial take here?
- 6:55Speaker 2: Mighty Sick introduces them as patterns enclosed and forward slashes
- 6:58Speaker 2: like pattern okay, and these can be followed by optional
- 7:01Speaker 2: flags to modify their behavior, like g is for global
- 7:04Speaker 2: matching finding all occurrences, not just the first one, and
- 7:08Speaker 2: he makes the match case insensitive standard flags. Yeah. A
- 7:12Speaker 2: key concept within rejecks is capturing groups. You create these
- 7:16Speaker 2: by putting parts of the pattern in parentheses right to.
- 7:19Speaker 1: Pull out specific parts of the match precisely.
- 7:21Speaker 2: These groups are numbered from left to right, starting with one.
- 7:25Speaker 2: Group zero usually represents the entire match, and these captured
- 7:28Speaker 2: groups are incredibly useful. For instance, in a string's replace method,
- 7:32Speaker 2: you can use one dollar, two dollars, et cetera in
- 7:34Speaker 2: your replacement string to refer back to whatever those groups captured.
- 7:38Speaker 1: That bag referencing is really powerful. What about common string
- 7:42Speaker 1: methods that use regular expressions?
- 7:44Speaker 2: Several core string methods really leverage rejects. Search rejects gives
- 7:49Speaker 2: you the index of the first match, or make it
- 7:51Speaker 2: a one. If no match, replace rejects replacement substitutes matches.
- 7:55Speaker 2: If you use the G flag, it replaces all occurrences.
- 7:59Speaker 1: Makes sense.
- 7:59Speaker 2: Match read returns an array with the matches. If you
- 8:02Speaker 2: use G it's an array of all matched substrings. Without
- 8:05Speaker 2: G it's the first match plus any captured groups.
- 8:08Speaker 1: AH different behavior.
- 8:09Speaker 2: With G yep. Then there's match all pattern, which, especially
- 8:13Speaker 2: with a G flag, returns an iterator of all matches.
- 8:16Speaker 2: Really handy for four of flups and split regixt divides
- 8:19Speaker 2: a string into an array of substrings using the rejects
- 8:22Speaker 2: pattern as the delimitter. Plus there are methods directly on
- 8:25Speaker 2: the rigix object itself, like exec string, which finds an
- 8:28Speaker 2: next match in tracks position, and test ring, which is simpler,
- 8:31Speaker 2: just returns true or false if there's a match.
- 8:33Speaker 1: Okay, that gives us a solid initial grasp. Let's move
- 8:36Speaker 1: on to naming things identifiers. What are the basic rules?
- 8:40Speaker 2: Identifiers in the names for variables, functions, etc. Must start
- 8:44Speaker 2: with a letter, an underscore, ick, or a dollar sign.
- 8:47Speaker 1: No numbers at the start.
- 8:49Speaker 2: Correct subsequent characters can be letters, digits, underscores, or dollar
- 8:53Speaker 2: signs by convention. Variable and function names usually start lowercase
- 8:58Speaker 2: and use camel case like user profile.
- 9:00Speaker 1: Okay.
- 9:01Speaker 2: Class names typically start uppercase pascal case like user profile,
- 9:05Speaker 2: and constants are often written in all uppercase letters.
- 9:08Speaker 1: Standard conventions pretty much.
- 9:10Speaker 2: Of course, you can't use javascripts reserve keywords let, const, iff,
- 9:13Speaker 2: et cetera as identifiers.
- 9:15Speaker 1: Clear and consistent conventions are always helpful. Now, when we
- 9:19Speaker 1: declare variables, JavaScript gives us let and const. What's the
- 9:23Speaker 1: core difference a programmer needs to know? So?
- 9:26Speaker 2: JavaScript is dynamically typed, meaning you don't declare the type,
- 9:29Speaker 2: and variables can hold different types over time. You declare
- 9:32Speaker 2: variables using let, you can initialize them then or assign
- 9:36Speaker 2: a valulator.
- 9:37Speaker 1: Okay, let is for changeable variables.
- 9:39Speaker 2: Right. Cost is used to declare constants. Unlike lead. You
- 9:43Speaker 2: must assign a value to a const when.
- 9:45Speaker 1: You declare it, and it can't be reassigned.
- 9:47Speaker 2: The binding can't. Yes, yeah, but here's a key point.
- 9:51Speaker 2: If the cost variable holds an object or an array,
- 9:54Speaker 2: the contents of that object or array can still be modified.
- 9:58Speaker 1: Ah, So const protects the ass assignment, not the value itself.
- 10:01Speaker 1: If it's mutable.
- 10:02Speaker 2: Exactly, const means the binding is constant, not necessarily that
- 10:05Speaker 2: the value is immutable.
- 10:06Speaker 1: Got it let for reassignable variables, costs for variables intended
- 10:09Speaker 1: to hold a constant reference. Now, how do we actually
- 10:11Speaker 1: operate on these values? Key operators?
- 10:14Speaker 2: JavaScript offers a pretty familiar set arithmetic plus kein ivelo percent,
- 10:19Speaker 2: remainder and exponentiation, boolean logic andy andy and di enda
- 10:23Speaker 2: nuts fame comparisons any dotic loose inequality, US strict inequality,
- 10:27Speaker 2: string concatenation uses plus rocks, assignment operators plus and so on,
- 10:31Speaker 2: the usual shorthand unary plus and ddea, and the ternary
- 10:35Speaker 2: operator condition value false value false for concise conditionals.
- 10:40Speaker 1: Okay, seems familiar. Any particular pitfalls or best practices with
- 10:45Speaker 1: these operators in JavaScript?
- 10:47Speaker 2: Yes, a couple of really crucial ones. First, be very
- 10:51Speaker 2: cautious comparing floating point numbers for exact equality using in.
- 10:56Speaker 1: Ah the classic floating point.
- 10:57Speaker 2: Issue exactly due to their internal representation, things might not
- 11:01Speaker 2: compare is equal when you expect them to. Matusex suggests
- 11:04Speaker 2: a workaround. Convert them to strings with a fixed number
- 11:08Speaker 2: of decimal places using to fixed in, and then compare
- 11:10Speaker 2: the strings.
- 11:11Speaker 1: Interesting workaround what's the second big one?
- 11:13Speaker 2: Understanding the difference between in at and endear. This is
- 11:17Speaker 2: huge in JavaScript, at least versus strict right. The loose
- 11:21Speaker 2: equality attempts type coercion. It tries to convert operands of
- 11:25Speaker 2: different types before comparing them. This leads to some surprising,
- 11:29Speaker 2: often undesirable results like undefined null is actually.
- 11:33Speaker 1: True WHOA okay.
- 11:35Speaker 2: Whereas the strict equality compares both the value and the
- 11:38Speaker 2: type without any type coercion, It's almost always the safer
- 11:42Speaker 2: and preferred choice.
- 11:43Speaker 1: So rule of thumb, use triple.
- 11:45Speaker 2: Equals generally yes. Also, remember object comparison. When you compare
- 11:50Speaker 2: objects including arrays and functions with eat or or, you're
- 11:55Speaker 2: checking if they are the exact same object in memory
- 11:57Speaker 2: now that they have the same.
- 11:58Speaker 1: Contents right so VERI one would be false.
- 12:01Speaker 2: Correct because there are two distinct array objects even though
- 12:03Speaker 2: they look the same and related to that object. Assignment
- 12:06Speaker 2: creates references. If you assign OBJA to OBJB, both variables
- 12:10Speaker 2: point to the same object, modifying through OBJA effects OBGB.
- 12:14Speaker 1: Those are critical distinctions, especially loose versus strict equality and
- 12:18Speaker 1: object identity versus value. Now, how do we structure our
- 12:20Speaker 1: code using statements.
- 12:22Speaker 2: Again, if you're coming from Java or C plus plus wave,
- 12:25Speaker 2: much of JavaScript's statement syntax will feel very familiar. You
- 12:29Speaker 2: have standard variable assignments, expressions used for side effects like
- 12:33Speaker 2: function calls, blocks of code grouped by curly braces to
- 12:36Speaker 2: define scope, and the usual control flow e false for
- 12:40Speaker 2: conditions while up and double loops, and the four loop
- 12:44Speaker 2: for iteration. Okay, one small detail. The initialization part of
- 12:49Speaker 2: a for loop in modern JavaScript typically uses lead to
- 12:52Speaker 2: declare the loop, counter scoping it nicely to just the loop.
- 12:56Speaker 2: Good practice, and JavaScript switch statement is maybe a bit
- 12:59Speaker 2: more flexible the case. Clauses can evaluate expressions, not just
- 13:03Speaker 2: constant values, so.
- 13:04Speaker 1: The fundamental control flow is quite similar. What about statements
- 13:07Speaker 1: that are more unique to JavaScript or have specific nuances.
- 13:11Speaker 2: There are a few that stand out. Four of specifically
- 13:14Speaker 2: designed for iterating over the values of iterable.
- 13:17Speaker 1: Objects, like a raise sets strings.
- 13:19Speaker 2: See exactly A ray sets map strings. Plain user defined
- 13:23Speaker 2: objects aren't itterable by default, that you can make them miserable.
- 13:25Speaker 1: Okay, And four in fian iterates over.
- 13:28Speaker 2: The property names or keys of an object. Yeah, you
- 13:32Speaker 2: can use it with user defined objects. A raise where
- 13:35Speaker 2: it iterates index names as strings. Even strings iterating indices,
- 13:39Speaker 2: but be aware it iterates over inherited innumerable properties too,
- 13:43Speaker 2: and it might skip missing elements and sparse arrays. So
- 13:46Speaker 2: it has its uses, But Forurian is often preferred for
- 13:49Speaker 2: iterating values in collections.
- 13:51Speaker 1: Gotcha, what else?
- 13:52Speaker 2: The throw statement lets you intentionally raise an exception. Interestingly,
- 13:56Speaker 2: in JavaScript you can throw a value of any type,
- 13:58Speaker 2: not just specific.
- 13:59Speaker 1: Air object, really any type.
- 14:01Speaker 2: Yep, And there isn't a strict distinction like checked versus
- 14:04Speaker 2: unchecked exceptions found in some other languages.
- 14:07Speaker 1: And how do we handle these thrown values, these exceptions.
- 14:10Speaker 2: That's where the tricatch finally block comes in code that
- 14:13Speaker 2: my throw goes in the try block. Standard If an
- 14:16Speaker 2: exception happens, control jumps to the catch block. You can
- 14:19Speaker 2: have an optional variable in catch to hold the throne value. Okay,
- 14:22Speaker 2: and the finally block, if you include it, always executes
- 14:25Speaker 2: after trying cash whether an exception occurred or not. Great
- 14:28Speaker 2: for cleanup makes sense. An interesting quirk If try or
- 14:31Speaker 2: catch has a return, break or continue, its execution is
- 14:35Speaker 2: sort of paused until the finally block finishes.
- 14:38Speaker 1: Oh, okay, finally really means finally pretty much.
- 14:42Speaker 2: JavaScript also has labeled statements label name that statement. They're
- 14:46Speaker 2: mainly useful with break and continue inside nest of loops
- 14:49Speaker 2: or switch statements. Break label name exits the specific label
- 14:53Speaker 2: loop or switch continue label name jumps to the next
- 14:56Speaker 2: iteration of the labeled loop.
- 14:58Speaker 1: Allows for more fine grained control in nested structures.
- 15:01Speaker 2: Exactly and Finally, the return statement sends a value back
- 15:04Speaker 2: from a function. If there's no return, or just return,
- 15:08Speaker 2: the function implicitly returns undefined functions mainly used for side
- 15:11Speaker 2: effects are sometimes called procedures.
- 15:13Speaker 1: That's a good overview of JavaScript's control flow. Let's move
- 15:16Speaker 1: on to functions. A cornerstone.
- 15:18Speaker 2: Absolutely the most common way to define what is function?
- 15:20Speaker 2: Function name, param one, PERM.
- 15:22Speaker 1: Two standard syntax.
- 15:23Speaker 2: When working in HTMOL, it's generally good practice to define
- 15:26Speaker 2: functions in script tags inside the head. This ensures they're
- 15:30Speaker 2: defined before any code in the body tries to call them.
- 15:32Speaker 1: Makes sense.
- 15:33Speaker 2: Functions can be recursive call themselves. They can be nested
- 15:36Speaker 2: inside other functions. Variables declared inside, including parameters, have local scope,
- 15:42Speaker 2: but functions can access variables from their outer environment up
- 15:46Speaker 2: to the global scope unless shadowed.
- 15:48Speaker 1: Locally standard lexical scoping right.
- 15:51Speaker 2: One key concept to knowe is.
- 15:52Speaker 1: Hoisting ah hoisting.
- 15:54Speaker 2: Function declarations and variables declared with var the older way
- 15:59Speaker 2: are conception moved to the top of their scope during compilation.
- 16:03Speaker 1: So you can sometimes call a function before its definition appears.
- 16:06Speaker 2: In the code. Technically yes, but it's generally much better
- 16:09Speaker 2: practice to define functions before you use them, just for
- 16:12Speaker 2: clarity and predictability.
- 16:14Speaker 1: Hoisting another one of JavaScript's interesting behaviors to keep in mind. Now,
- 16:18Speaker 1: testing is crucial. Does Matischik's touch on that.
- 16:21Speaker 2: He does include a brief introduction. He mentions using the
- 16:24Speaker 2: Mocha testing framework and the Chai assertion.
- 16:26Speaker 1: Library common tools yeah for.
- 16:28Speaker 2: Writing and running tests, often within a browser. For client
- 16:31Speaker 2: side code. He outlines the basic structure describe blocks to
- 16:35Speaker 2: group tests, it blocks for individual test cases with descriptive
- 16:38Speaker 2: names inside it. Use assertions from Chi's assert object to
- 16:42Speaker 2: check if your code behaves as expected. He shows examples
- 16:46Speaker 2: like assert dot is true, assert dot is false, assert
- 16:49Speaker 2: dot equal for loose equality.
- 16:52Speaker 1: AH, loose again. Is there a strict one?
- 16:54Speaker 2: Yes, assert dot strict equal and not equal not strict equal.
- 16:58Speaker 2: He also mentions assert dot org approximately for comparing floats
- 17:01Speaker 2: within a tolerance.
- 17:03Speaker 1: Good for those floating point comparisons we talked about exactly.
- 17:06Speaker 2: He briefly covers setting up Mocha and Chai in an
- 17:09Speaker 2: HTML page, maybe using CD in links, and initializing Mocha
- 17:13Speaker 2: to run the tests.
- 17:13Speaker 1: A quick taste of the testing landscape. Good to know
- 17:16Speaker 1: it's covered. Now the book moves into JavaScript in more detail.
- 17:20Speaker 1: What key enhancements and deeper concepts does it explore there?
- 17:23Speaker 2: Right? This section builds on the basics getting nuance in
- 17:26Speaker 2: introducing more advanced features. It starts with destructuring.
- 17:29Speaker 1: Destructuring I like the sound of that.
- 17:31Speaker 2: It's really elegant. A concise way to extract values from
- 17:34Speaker 2: objects and arrays and assign them directly to variables you
- 17:38Speaker 2: use for objects and for arrays on the left side of.
- 17:40Speaker 1: An assignment, so you can pull out just the pieces
- 17:43Speaker 1: you need exactly.
- 17:44Speaker 2: You can pull out specific properties or elements. You can
- 17:47Speaker 2: even rename properties during extraction, like let username nice, and
- 17:50Speaker 2: you can provide default values if a property might be
- 17:53Speaker 2: missing nice. It's especially powerful in function parameter lists. You
- 17:57Speaker 2: can destructure an object passed as an argument right in
- 18:00Speaker 2: the parameter definition.
- 18:01Speaker 1: Destructuring sounds like a great tool for cleaner, more readable code.
- 18:05Speaker 1: What about revisiting data types? With a more in depth
- 18:08Speaker 1: look any more nuances.
- 18:10Speaker 2: Yes, numbers again reiterated. They're mostly sixty four bit i
- 18:14Speaker 2: ee seven hundred and fifty four floats except for bigot.
- 18:17Speaker 2: He mentions the special values infinity, infinity, and nan not
- 18:21Speaker 2: a number right nan, and the is finite function to
- 18:24Speaker 2: check for actual finite numbers. Also useful constants like number
- 18:28Speaker 2: dot mn value, number dot x value and number dot
- 18:31Speaker 2: epsilon that tiny difference.
- 18:33Speaker 1: Value okay, strings.
- 18:35Speaker 2: Key point is immutability. Once created, you can't change individual characters.
- 18:39Speaker 2: You can access characters by index read only. He details
- 18:43Speaker 2: escape characters like n and unicode escapes.
- 18:44Speaker 1: Too right, and symbols you mentioned those briefly.
- 18:47Speaker 2: Symbols are unique, immutable primitive values oh created with symbol
- 18:52Speaker 2: even symbol desks create two different.
- 18:54Speaker 1: Symbols guaranteed uniqueness. What are they used for?
- 18:57Speaker 2: Often used as unique property keys on odds. Maybe to
- 19:00Speaker 2: add metadata or behavior without risking name collisions with other
- 19:04Speaker 2: properties or future language editions.
- 19:06Speaker 1: Clever. What about advanced array and set operations for arrays?
- 19:11Speaker 2: He mentions unshift and shift for adding removing from the beginning,
- 19:15Speaker 2: but notes they can be less efficient than push pop.
- 19:17Speaker 2: At the end, he also highlights Han's own property. It's
- 19:22Speaker 2: a reliable way to check if an object, including an
- 19:25Speaker 2: array actually has a property directly on itself, not inherited,
- 19:28Speaker 2: and useful for distinguishing real elements from undefined slots in
- 19:32Speaker 2: sparse arrays. Such JavaScript doesn't have built in methods for
- 19:35Speaker 2: standard set operations like union, intersection, difference. Oh really yeah,
- 19:40Speaker 2: but metwusex shows how you can implement them yourself, using
- 19:43Speaker 2: the spread syntax to convert sets to arrays and then
- 19:46Speaker 2: using array methods like filter along with the sets as method.
- 19:49Speaker 1: So a bit of manual work for those. What about
- 19:53Speaker 1: maps and weak maps? How do they differ?
- 19:55Speaker 2: Maps are key value collections where keys can be any
- 19:58Speaker 2: data type, objects, function primitives. Key equality is based on identity.
- 20:03Speaker 1: Okay.
- 20:04Speaker 2: He cautions that if you use object literals as keys
- 20:07Speaker 2: at one and ad on one are different keys because
- 20:09Speaker 2: they're different objects in memory, you need to use the
- 20:12Speaker 2: same object instance right.
- 20:13Speaker 1: Identity matters.
- 20:14Speaker 2: Week maps week maps are specialized. Keys must be objects
- 20:18Speaker 2: and they're held.
- 20:19Speaker 1: Weekly weekly meaning.
- 20:21Speaker 2: Meaning if the object used as a key is no
- 20:23Speaker 2: longer referenced anywhere else, it can be garbage collected and
- 20:26Speaker 2: the entry automatically disappears from the weak.
- 20:28Speaker 1: Map ah for memory management.
- 20:30Speaker 2: Exactly because of this week, maps aren't iterable and have
- 20:34Speaker 2: limited methods get said has delete. Their state can be
- 20:38Speaker 2: nondeterministic due to garbage collection timing.
- 20:41Speaker 1: Niche but potentially powerful. Let's move to promises fundamental for
- 20:46Speaker 1: async JavaScript.
- 20:47Speaker 2: Yes, promises handle results of asynchronous operations like network requests.
- 20:51Speaker 2: You create one with new promise function resolve, reject.
- 20:55Speaker 1: The executor function right it.
- 20:56Speaker 2: Gets resolved, and reject functions You call resolvevol with the
- 21:00Speaker 2: result on success, reject with an error on failure. Promises
- 21:04Speaker 2: capture their surrounding environment. When created. You handle the results
- 21:08Speaker 2: using then unfulfilled, unrejected or then unfulfilled catch unrejected.
- 21:13Speaker 1: Chaining the dot chain is key very much.
- 21:15Speaker 2: So it's how you sequence asynchronous actions.
- 21:18Speaker 1: Okay, what about the finer points of type conversions coercion.
- 21:22Speaker 2: JavaScript does a lot of automatic conversion coercion. You can
- 21:25Speaker 2: also do explicit conversions using number straing, boolean big, and
- 21:30Speaker 2: parson pars float. He warns against using new with number
- 21:34Speaker 2: string or boolean That creates wrapper objects not primitives, which
- 21:38Speaker 2: can cause confusion.
- 21:39Speaker 1: Good tip.
- 21:40Speaker 2: All objects have a toe string method. Good practice to
- 21:43Speaker 2: override it. For custom objects, parsint and parse float try
- 21:47Speaker 2: to parse numbers from the start of a string, stopping
- 21:49Speaker 2: at the first non numeric character, or non numeric after
- 21:52Speaker 2: a decimal.
- 21:53Speaker 1: For pars float, good to know how they handle non
- 21:55Speaker 1: numeric parts. The book lists keywords too. Any key advice
- 21:58Speaker 1: there besides.
- 21:59Speaker 2: The obvious don't use keywords as names. He suggests avoiding
- 22:03Speaker 2: older reserved words, even if not strictly enforced. Now built
- 22:06Speaker 2: in object property method names, htmail, element attribute names and
- 22:11Speaker 2: event handler names basically choose descriptive names that won't clash.
- 22:16Speaker 1: Sound advice. Now you mentioned good and bad operators earlier,
- 22:19Speaker 1: can you elaborate?
- 22:21Speaker 2: He discusses operator precedence, order of operations, and associativity for
- 22:26Speaker 2: operators with same precedence. There's a table outlining this. For
- 22:29Speaker 2: key operators, he highlights logical and A and R as
- 22:33Speaker 2: short circuiting.
- 22:33Speaker 1: Meaning they don't always evaluate the second part exactly.
- 22:36Speaker 2: And aaran stops if the left side is falsey yeah
- 22:39Speaker 2: stops if the left side is truthy. They often return
- 22:42Speaker 2: the value of the operand that determine the result not
- 22:44Speaker 2: necessarily true orful right.
- 22:46Speaker 1: The Y five default value trick yep.
- 22:48Speaker 2: Then there's the nullish coalescing operator. Yeah. It returns the
- 22:51Speaker 2: right operad only if the left one is null or undefined.
- 22:54Speaker 2: Otherwise it returns the left operand.
- 22:56Speaker 1: So it's stripter than which triggers on any falsey correct.
- 23:01Speaker 2: He stresses using parentheses when mixing with milan or due
- 23:05Speaker 2: to precedence rules. As for bad operators, he references Crockford's
- 23:09Speaker 2: JavaScript The good parts. For instance, the prefixed postfix increment,
- 23:13Speaker 2: plus plus and decrement operators are sometimes discouraged. Why is
- 23:17Speaker 2: that they can make code less clear, especially when used
- 23:21Speaker 2: inside complex expressions. Using plus one or nakeld one is
- 23:24Speaker 2: often more explicit and less aero prone.
- 23:27Speaker 1: Readability and avoiding subtle bugs good principles. Let's revisit functions
- 23:31Speaker 1: more details in this section.
- 23:32Speaker 2: Definitely several ways to define them. The standard function declaration
- 23:36Speaker 2: function expressions. Assigning function to a variable can be anonymous
- 23:39Speaker 2: or named. The function constructor takes code as strings. Generally
- 23:43Speaker 2: bad idea right, avoid that one and erow functions which
- 23:46Speaker 2: have concise syntax and crucially lexical this binding.
- 23:49Speaker 1: Welcome back to this right.
- 23:51Speaker 2: All functions have a name property. JS tries to infer
- 23:54Speaker 2: it parameter versus argument distinction parameters and definition arguments in
- 23:59Speaker 2: the call JS doesn't enforce matching counts. Extra ARGs ignored
- 24:02Speaker 2: missing ones are undefined.
- 24:04Speaker 1: Flexible, but potentially error prone if you're not careful.
- 24:07Speaker 2: True. The older arguments object array like list of all
- 24:11Speaker 2: orgs and traditional functions is mentioned, but rest parameters dot
- 24:15Speaker 2: org are generally preferred.
- 24:16Speaker 1: Now okay.
- 24:17Speaker 2: Key concept functions are first class data. Assign them to variables,
- 24:22Speaker 2: put them in a raise, pass them as arguments callbacks.
- 24:26Speaker 2: A function's toastring returns its source code. Its length property
- 24:30Speaker 2: is the number of declared parameters excluding rest.
- 24:33Speaker 1: Functions as values is super powerful it is He revisits
- 24:37Speaker 1: recursion with a factorial example.
- 24:39Speaker 2: You can add properties directly to a function object itself,
- 24:42Speaker 2: like myfunk dot counter equals zero as an alternative to
- 24:46Speaker 2: globals sometimes and he briefly mentions dot call, dot ply
- 24:50Speaker 2: and dot bind for controlling this value during invocation.
- 24:53Speaker 1: Right controlling execution context. Now generators function what's the deeper doug.
- 24:58Speaker 2: Generators are special functions that can pause and resume. Defined
- 25:01Speaker 2: with function calling one doesn't run it, but returns a
- 25:04Speaker 2: generator object, which is an iterator inside the yield keyword
- 25:08Speaker 2: returns a value and pauses execution. Calling next on the
- 25:12Speaker 2: generator object resumes it until the next yield or the end,
- 25:15Speaker 2: and next returns an object like the yielded value done false.
- 25:20Speaker 2: When the generator finishes, reaches an end or hits a return,
- 25:24Speaker 2: next returns value final value or undefined done through. Once done,
- 25:29Speaker 2: it's done, can't restart it, Nope. They're great for creating
- 25:32Speaker 2: custom iterators easily. He shows a simple half end generator example.
- 25:36Speaker 1: Generators sound useful for sequences and that ties into iterators
- 25:39Speaker 1: and iterables exactly.
- 25:41Speaker 2: An object is iterable if it implements the iterable protocol.
- 25:44Speaker 2: That means having a method keyed by the special symbol
- 25:47Speaker 2: symbol dot iterator. This method must return an iterator object
- 25:51Speaker 2: which has a next method. Often the easiest way to
- 25:53Speaker 2: implement symble dot iterator is just to make it a
- 25:55Speaker 2: generator function. Mitisek shows an example making an object with start,
- 25:59Speaker 2: step and iterable using a generator.
- 26:02Speaker 1: So that's the magic behind how four off works on
- 26:04Speaker 1: different things. Finally, let's really get into the details of
- 26:07Speaker 1: objects themselves.
- 26:08Speaker 2: Right, objects are fundamental collections of key value pairs. Create
- 26:12Speaker 2: them with literals key dot value meat keyser useles, strings
- 26:16Speaker 2: or symbols, access with dot, a bracket and notation.
- 26:18Speaker 1: We covered the shorthand.
- 26:20Speaker 2: Yeah. If you have a variable let make toyota and
- 26:22Speaker 2: want an object make toyota, you just write that make
- 26:26Speaker 2: nice shortcut cool. Checking for properties, the in operator checks
- 26:30Speaker 2: if a property exists, including inherited ones. Fore end loops
- 26:33Speaker 2: over innumerable property names including inherited okay. Creating objects literals,
- 26:38Speaker 2: object adding properties dynamically, constructor functions with new using this
- 26:43Speaker 2: inside yeah and object dot create prototype, which creates a
- 26:46Speaker 2: new object with a specific prototype you provide.
- 26:49Speaker 1: And copying objects still just.
- 26:50Speaker 2: References, still just references. Assignment copies the reference, not the object.
- 26:55Speaker 2: Modifying one effects the other if they point to the
- 26:57Speaker 2: same object. Methods are just functions that are are properties
- 27:00Speaker 2: of an object. Concise syntax and literals.
- 27:03Speaker 1: My method, got it now? This keyword always a fun
- 27:07Speaker 1: one has it explained here.
- 27:09Speaker 2: Its value is determined by how a function is called,
- 27:13Speaker 2: the call site evaluated at run time. Inside a method
- 27:17Speaker 2: called like UBJ dot method, this is usually object. In
- 27:20Speaker 2: a constructor called with new, this is the new object
- 27:23Speaker 2: being created. Makes sense in a regular function called directly,
- 27:27Speaker 2: not as a method in non strict mode, this is
- 27:30Speaker 2: the global object window and browsers, but in strict mode
- 27:34Speaker 2: it's undefined.
- 27:36Speaker 1: AH. Strict mode changes things again.
- 27:38Speaker 2: Yes, and a function inside another function. This inside the
- 27:41Speaker 2: inner one follows the regular function rules. It doesn't automatically
- 27:45Speaker 2: inherit the outer this unless unless it's an erowfunction. Erofunctions
- 27:49Speaker 2: capture this value from their surrounding lexical scope. They don't
- 27:55Speaker 2: have their own this binding.
- 27:56Speaker 1: That's a key difference for EROW functions.
- 27:58Speaker 2: Event handlers femail event handlers. This usually refers to the
- 28:02Speaker 2: htmail element that triggered.
- 28:03Speaker 1: The events, so context is everything for this. You've mentioned
- 28:06Speaker 1: prototypes a lot. Let's nail that down.
- 28:08Speaker 2: Every JavaScript object has an internal link to another object,
- 28:11Speaker 2: its prototype. You can get it with object dot get prototype.
- 28:14Speaker 2: When you access a property, If the object doesn't have
- 28:17Speaker 2: it directly, JavaScript looks at its prototype. If it's not there,
- 28:21Speaker 2: it looks at the prototypes prototype, and so on up
- 28:23Speaker 2: the chain.
- 28:24Speaker 1: The prototype chain exactly.
- 28:26Speaker 2: Until it finds the property or hits the end where
- 28:28Speaker 2: the prototype is null. Object dot prototype is the base
- 28:31Speaker 2: for most objects. Setting a property always happens directly on
- 28:35Speaker 2: the object, never modifies the prototype chain directly like.
- 28:38Speaker 1: That and properties have hidden attributes descriptors Yes, properties.
- 28:42Speaker 2: Have attributes like innumerable, does it show and foreign writeable?
- 28:46Speaker 2: Can its value be changed? And configurable? Can it be
- 28:49Speaker 2: deleted or its attributes changed? You can control these with
- 28:53Speaker 2: object dot defined property.
- 28:54Speaker 1: Fine grained control. Now, how do classes fit in with prototypes?
- 28:58Speaker 2: Classes from e S twenty fifteen are mostly syntactic sugar
- 29:02Speaker 2: over the existing prototype based inheritance. They provide a clear
- 29:05Speaker 2: or more familiar syntax from many programmers, a blueprint kind
- 29:08Speaker 2: of my class constructor. Defining a class essentially creates a
- 29:12Speaker 2: constructor function and adds methods to its prototype property new
- 29:16Speaker 2: my class calls the constructor this inside refers to the instance,
- 29:21Speaker 2: and inheritance uses the extends keyword. Class subclass extends superclass.
- 29:26Speaker 2: The subclass prototype is linked to the superclass prototype inheriting methods.
- 29:31Speaker 2: You can override methods if no extends it implicitly extends object.
- 29:35Speaker 1: So classes organize the prototype stuff. Can we still mess
- 29:38Speaker 1: with prototypes directly with classes?
- 29:40Speaker 2: Yes, The my class dot prototype object holds the method
- 29:43Speaker 2: definition shared by all instances. You can still add methods
- 29:46Speaker 2: directly to my class dot prototype after the class definition
- 29:49Speaker 2: and all instances will get it. Object prototype of instance
- 29:53Speaker 2: still works. Object I creates still works. The underlying mechanism.
- 29:56Speaker 1: Is prototypes that clarifies the class prototype relationship. Now JavaScript evolves.
- 30:01Speaker 1: How do we handle older browsers that don't support new features?
- 30:04Speaker 2: Two main tools, transpilers and polyfills. Transpilers like Babble convert
- 30:09Speaker 2: newer syntax hegany aerofunctions classes into older compatible syntax. Polyfills
- 30:14Speaker 2: are pieces of code that provide implementations for features missing
- 30:17Speaker 2: in older environments, like if a browser doesn't have the
- 30:21Speaker 2: raate oup prototype dot includes method, you can include a
- 30:24Speaker 2: polyfil that adds it.
- 30:25Speaker 1: So transpilers handle syntax. Polyphils handle missing functions objects exactly.
- 30:30Speaker 2: Services like polyfil that io can even serve only the
- 30:33Speaker 2: polyfills needed by the specific browser making the request, but
- 30:36Speaker 2: you need to be mindful of download size.
- 30:38Speaker 1: Essential tools for cross browser compatibility. Last language topic before
- 30:42Speaker 1: the DOM.
- 30:43Speaker 2: Json json JavaScript object notation lightweight text format for data exchange,
- 30:48Speaker 2: very common.
- 30:49Speaker 1: How do we use it in JS?
- 30:51Speaker 2: Built in methods? Jsonstring ifi object converts a JS object
- 30:54Speaker 2: value into a Jason string. Json dot parse jsonstring converts
- 30:59Speaker 2: a jsonstring and do a JAS object value.
- 31:01Speaker 1: Simple enough any limitations.
- 31:03Speaker 2: Yes, Functions, symbols undefined are generally lost or become null
- 31:07Speaker 2: During stringification, dates become ISO format strings, infinity and nan
- 31:11Speaker 2: become null. Non innumerable properties and symbol keys are ignored, so.
- 31:15Speaker 1: It's mainly for plain data.
- 31:16Speaker 2: Structures pretty much. You can customize serialization by defining it
- 31:20Speaker 2: low chasm method on an object JSON dot string offy
- 31:23Speaker 2: will call that if it exists.
- 31:24Speaker 1: Good to know. Okay, let's shift gears to client side
- 31:27Speaker 1: JavaScript and the DOM. This is where it gets visual exactly.
- 31:30Speaker 2: The rest of the book focuses on guys and the
- 31:32Speaker 2: browser and using the DOM to interact with the page.
- 31:35Speaker 2: It starts with some essential HTML review right the structure
- 31:38Speaker 2: HML page is a text file with tags container tags,
- 31:41Speaker 2: tag content tag, empty tags like BR basic structure doctri
- 31:45Speaker 2: type HDL HTML head with title body. Tags can have
- 31:51Speaker 2: attributes name value like AID HTML tags attributes are case
- 31:55Speaker 2: in sensitive, but JS is case sensitive, CSS handles is
- 31:58Speaker 2: styling and.
- 31:59Speaker 1: How do we connect our jawas script to the HTML.
- 32:01Speaker 2: A few ways embedcode directly in script tags in header body, Yeah,
- 32:04Speaker 2: link to external JS files using script as rc URLJS
- 32:07Speaker 2: script usually in head if you use src code inside
- 32:11Speaker 2: the tags is ignored.
- 32:12Speaker 1: External files are generally better for organization.
- 32:14Speaker 2: Yes, especially for larger scripts. You can also use evan
- 32:17Speaker 2: handler attributes like on click JS code directly on HTML elements,
- 32:21Speaker 2: though separating JS is often cleaner. Function definitions best in head,
- 32:26Speaker 2: scripts and body execute as the page loads. NoScript provides
- 32:29Speaker 2: fallback content if JS is off.
- 32:31Speaker 1: Okay, Now, the dom itself a tree of nodes.
- 32:35Speaker 2: Think of it as a live interactive map or tree,
- 32:38Speaker 2: representing everything on the page. Elements, attributes, text. JavaScript can
- 32:42Speaker 2: read and change this tree. Any changes JavaScript makes to
- 32:45Speaker 2: the damber reflected immediately in the browser window. That's the
- 32:48Speaker 2: core of dynamic web.
- 32:49Speaker 1: Pages, a live tree we can modify. Let's start building
- 32:51Speaker 1: things widgets and events. Buttons.
- 32:54Speaker 2: The two skip covers buttons. First two ways input type,
- 32:57Speaker 2: button value click me or button click me button. The
- 33:00Speaker 2: button tag is newer, more flexible, can contain images, et cetera.
- 33:03Speaker 2: Requires a closing tag. JS can change button text value
- 33:06Speaker 2: for input inner HTML for button.
- 33:07Speaker 1: How do we find these buttons in our code?
- 33:09Speaker 2: Need to find the widgets document dot G element B
- 33:12Speaker 2: I E E finds the single element with a unique ID.
- 33:16Speaker 2: Document dot G elements be by tag name. Tagname gets
- 33:19Speaker 2: a live collection of all elements with that tag.
- 33:21Speaker 1: Get element by i'd for specifics, get elements by tag
- 33:24Speaker 1: name for groups text fields for user input use.
- 33:27Speaker 2: Input type text can set size for a visible width
- 33:31Speaker 2: value for initial text. To get user input, find the
- 33:34Speaker 2: element again by ID and read its dot value property
- 33:38Speaker 2: in JavaScript simple enough? How do HTML forms fit in
- 33:41Speaker 2: form acts as a container for related inputs, usually for
- 33:44Speaker 2: submitting data. Submit buttons type submit, trigger, submission, reset buttons
- 33:48Speaker 2: type reset clear the form plain buttons type button do
- 33:52Speaker 2: nothing by default. A button inside a form default to
- 33:55Speaker 2: type submit if unspecified. Okay forms define a scope for
- 33:59Speaker 2: the name attribute on inputs. This name identifies the data
- 34:03Speaker 2: when submitted. I must be unique on the whole page.
- 34:06Speaker 2: Forms can't be nested. Pressing it entering an input field
- 34:09Speaker 2: often submits the form if there's a submit put.
- 34:11Speaker 1: Forms group inputs for submission. How about validation? Making sure
- 34:14Speaker 1: input is.
- 34:15Speaker 2: Okay HTAM all five added built in validation attributes required,
- 34:18Speaker 2: makes a field mandatory, pattern rejects checks input against a
- 34:22Speaker 2: regular expression. Placeholder text gives a hint, and.
- 34:25Speaker 1: Built in checks are nice.
- 34:26Speaker 2: Custom validation use the unsubmitted vent handler on the form tag,
- 34:30Speaker 2: set it to return my function. If my function returns false,
- 34:33Speaker 2: submission is canceled. Inside the function. You can use event
- 34:36Speaker 2: dot prevent to fall two.
- 34:37Speaker 1: Client side validation gives quick feedback what happens on successful submission.
- 34:41Speaker 2: The action you URL attribute on the form says where
- 34:44Speaker 2: to send data, method says how Usually get or post.
- 34:48Speaker 2: Get appens data to URL, post sends it in the
- 34:51Speaker 2: request body.
- 34:52Speaker 1: Okay, any other useful text widgets.
- 34:55Speaker 2: Input type email, checks for at, input type, numbers, spinners,
- 34:59Speaker 2: input type earl, basic, url, check textteria for multiline input
- 35:04Speaker 2: daytime inputs exist, but support varies.
- 35:06Speaker 1: Good range. What about non text inputs, radio, buttons, checkboxes.
- 35:10Speaker 2: Input type radio used in groups with the same name.
- 35:13Speaker 2: Selecting one d selects others in the group. Input type
- 35:15Speaker 2: checkdocs are independent selections others. Input type image src images,
- 35:19Speaker 2: submit button, input type color colorpicker, input type hidden data
- 35:24Speaker 2: smitted but not visible, input type range slider.
- 35:27Speaker 1: Lots of input types. Now how do these react to users? Events?
- 35:31Speaker 2: Events are actions user clicks, keypresses, pageloads handled by attributes
- 35:36Speaker 2: like on click JS code. Event names are a lowercase
- 35:39Speaker 2: in HTML attributes on click often CamelCase and JS on
- 35:42Speaker 2: click common events dot onload onload for bodyframes, mouse dot on,
- 35:47Speaker 2: click on, be able to click on mouse down on
- 35:49Speaker 2: mouse up on mouseover on mouse out on mass move,
- 35:51Speaker 2: pointer events on pointer out, unify, mouse touch, focus, dot on,
- 35:55Speaker 2: focus on, blur, change on, change on select form, dot on,
- 35:58Speaker 2: reset on submit return false, camp image, dot on a
- 36:01Speaker 2: board on error, keyboard dot donkey down on keypress, event
- 36:04Speaker 2: dot key on KIAP.
- 36:06Speaker 1: That's a lot of events. What's in the event object?
- 36:08Speaker 2: The event object pass to Handlers have info like event
- 36:11Speaker 2: dot type ag click, and event dot target the element.
- 36:14Speaker 1: That triggered the A M bubbling. What's that?
- 36:16Speaker 2: When an event happens on an element, it bubbles up
- 36:18Speaker 2: the DOM tree. First the target handles it, then its parent,
- 36:21Speaker 2: then its parent's parent, all the way up.
- 36:23Speaker 1: So a click on a button also clicks the div
- 36:25Speaker 1: it's inside and the body potentially yes.
- 36:28Speaker 2: Each ancestor gives a chance to handle the event unless
- 36:31Speaker 2: a handler stops propagation. It's useful for event delegation, handling
- 36:34Speaker 2: events for many children by listening on a parent efficient.
- 36:37Speaker 1: Okay, let's dive deeper into using the dom manipulating that
- 36:41Speaker 1: tree right.
- 36:42Speaker 2: Starts with a window object. It's the global object. In browsers,
- 36:45Speaker 2: document is actually a property of window.
- 36:47Speaker 1: So window, dot, document and document are the same.
- 36:49Speaker 2: Usually yes, because window is the global scope, window represents
- 36:53Speaker 2: the browser. Window itself has properties like location, kurt url
- 36:57Speaker 2: can change it to navigate history, back, forward, navigateator, browser info.
- 37:01Speaker 1: What about methods on window.
- 37:03Speaker 2: User interaction, dot alert, proft, confirmed timers, dot delay runs
- 37:08Speaker 2: funk once after delay milliseconds, set interval, fagigible runs funk
- 37:13Speaker 2: repeatedly every interval milliseconds. Both return IDs to use with
- 37:17Speaker 2: clear timeout or clear interval to stop them. My two
- 37:19Speaker 2: sex shows using set timeout with window dot location for
- 37:22Speaker 2: a time to redirect.
- 37:23Speaker 1: Timers are key for dynamic stuff. What about finding nodes
- 37:26Speaker 1: Beyond the basics, we.
- 37:27Speaker 2: Have document dot body the body element, document the document
- 37:30Speaker 2: element to the HTML element. More finding methods. Document dot
- 37:34Speaker 2: elements by class name gets elements by class. Document dot
- 37:37Speaker 2: query selector gets the first element matching a CSS selector.
- 37:41Speaker 1: H ah, CSS selectors powerful very.
- 37:46Speaker 2: And document dot query selectoral selector gets all elements matching
- 37:49Speaker 2: the CSS selector, returning a static notalist. Much more flexible.
- 37:53Speaker 1: Targeting so we can find things precisely. How do we
- 37:56Speaker 1: create and add new things to the dawn.
- 37:58Speaker 2: Document dot create element tag name creates a new element node,
- 38:02Speaker 2: set its tech content with no dot text content equals text.
- 38:05Speaker 2: Add attributes with element dot set attribute name value.
- 38:09Speaker 1: Okay, create the node, How to put it on the page.
- 38:11Speaker 2: Use methods on the parentode where you want to add it.
- 38:13Speaker 2: Parentode dot penchild child node adds it at the end.
- 38:15Speaker 2: Parentnode dot insert before new nodes. Existing node inserts before
- 38:19Speaker 2: another child parentnode dot remove child noode removes it parentode
- 38:22Speaker 2: dot replaced child new noode. Old nodes swaps one for another.
- 38:25Speaker 1: Standard premanipulation copynotes.
- 38:27Speaker 2: No dot clone node deep. If deep is true, it
- 38:30Speaker 2: copies the node and everything inside it. If false, just
- 38:33Speaker 2: the node itself got it.
- 38:34Speaker 1: What about properties and methods specific to element objects.
- 38:37Speaker 2: Elements have element dot tag name oopcase element dot inner
- 38:41Speaker 2: HTML get sets the HTML content inside the element element
- 38:45Speaker 2: dot or HTML get sets the elements full HTML, including
- 38:48Speaker 2: its own tags. Element dot attributes is a collection of
- 38:51Speaker 2: attribute nodes. Element dot class name is the string of classes.
- 38:55Speaker 2: Element dot class list is better a list object with
- 38:58Speaker 2: ad remove toggle contains methods for classes. Element dot style
- 39:02Speaker 2: accesses inline styles.
- 39:04Speaker 1: Classless sounds much easier for managing classes elements specific methods.
- 39:08Speaker 2: They have their own get elements by class name, querity
- 39:10Speaker 2: selector query selectoral that search only within that element's descendants.
- 39:14Speaker 2: Also element dot, get attribute, element dot or room attribute,
- 39:17Speaker 2: and element dot insert adjacent HTML where htmail inserts HTML
- 39:21Speaker 2: strings relative to the element before begin after begin before whatever.
- 39:25Speaker 1: Insert adjacent HTML seems handy for adding chunks of HTML.
- 39:29Speaker 1: What about text nos character data.
- 39:31Speaker 2: Textnodes represent the actual text content. They have properties like data,
- 39:34Speaker 2: the text, and length. They have methods like a pen
- 39:36Speaker 2: data delete, data, replaced, data, and removed to manipulate or
- 39:40Speaker 2: remove the text.
- 39:41Speaker 1: Okay, the show tree example. What does that illustrate?
- 39:43Speaker 2: It's a practical demo. Usually a button click triggers JS
- 39:47Speaker 2: that recursively traverses the dom tree from document dot body down.
- 39:51Speaker 2: It logs info about each node name, attributes content to
- 39:56Speaker 2: the console. It really helps visualize that tree structure and
- 39:59Speaker 2: how JS can walk through it.
- 40:01Speaker 1: Seeing that tree logged out makes the dom much more concrete.
- 40:04Speaker 1: It sounds like, as the book's afterward notes, this is
- 40:07Speaker 1: a strong foundation for just a starting point.
- 40:10Speaker 2: Absolutely my t sake. It's clear it's not exhaustive, it's
- 40:13Speaker 2: an entry point for much more learning in the vast
- 40:15Speaker 2: world of JavaScript and webdev.
- 40:17Speaker 1: Well that brings us towards the end of this deep dive.
- 40:20Speaker 1: My key takeaway from quick JavaScript is its effectiveness for
- 40:23Speaker 1: experienced programmers needing a fast, targeted intro to JS and
- 40:27Speaker 1: the DOM. But you absolutely have to understand its scope,
- 40:30Speaker 1: who it's for, and what it deliberately leaves out.
- 40:33Speaker 2: Yeah, and it's fascinating reflecting on some of those Jamas
- 40:35Speaker 2: specific things we hit on, like it being the only
- 40:37Speaker 2: native browser language that type of null oddity, and the
- 40:40Speaker 2: whole prototype system underpinning objects, and even the newer class syntax.
- 40:45Speaker 1: And for you, our listener, we hope this dive gave
- 40:48Speaker 1: you that quick yet thorough understanding you needed, hitting the
- 40:51Speaker 1: essentials without getting bogged down in exhaustive detail.
- 40:55Speaker 2: We definitely encourage you now to explore the areas that
- 40:57Speaker 2: sparked your interest. Was it promise and async? Yeah, dug
- 41:01Speaker 2: deeper there, dom manipulation for interactivity, start building things robust code,
- 41:06Speaker 2: maybe look more into testing with Mocha and Chai.
- 41:09Speaker 1: And a final thought to leave you with, think about
- 41:11Speaker 1: JavaScript's journey. A language often described as being maybe hastily
- 41:15Speaker 1: put together initially has become this absolute powerhouse driving modern
- 41:19Speaker 1: web experiences. What does that evolution tell us about the
- 41:22Speaker 1: balance between say, initial design perfection versus continuous adaptation and
- 41:26Speaker 1: community driven growth and technology Something to ponder. Thanks for
- 41:29Speaker 1: joining us on this deep dive.