- Podcasts
- CyberSecurity Summary
- Quick JavaScript (Quick Programming)
About this episodeAn experienced programmer and educator, intends this resource for programmers already familiar with other languages (like C++ or Java) who…
You can listen and download our episodes for free on more than 10 different platforms:
https://linktr.ee/cyber_security_summary
Get the Book now from Amazon:
https://www.amazon.com/Quick-JavaScript-Programming-David-Matuszek/dp/1032417560?&linkCode=ll1&tag=cvthunderx-20&linkId=c22c48094a5516afc0341c1898f2a0b5&language=en_US&ref_=as_li_ss_tl
Discover our free courses in tech and cybersecurity, Start learning today:
https://linktr.ee/cybercode_academy
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Quick JavaScript (Quick Programming)
Today we're tackling a programmer's Quick Start Guide to Web Development Quick JavaScript by David Metusek. Our mission, driven by your need for efficient learning, is really to extract the core concepts of JavaScript and the HTML dom that experienced coders can grasp rapidly and thoroughly.
Indeed, and what's interesting right off the bat is who this book isn't for. Yeah, Metusk explicitly advises programming beginners to start with Python. That tells us a lot. It's laser focused on bringing established developers up to speed with JavaScript quickly. It assumes you already have a foundation in promming principles exactly.
Right, No, not at all. Matustik himself points readers looking for that really comprehensive reference towards Slannigan's JavaScript the Definitive Guide a classic, right, So quick JavaScript is about getting you hands on providing that crucial initial understanding of how JavaScript talks to and manipulates web pages through the document object model, the DOM. It's a targeted on ramp, and it's.
Think of you strict that exact string as like a safety switch for your JavaScript code. It was introduced in ekmascript twenty fifteen six. Okay, by putting that phrase at the beginning of your script or maybe inside of function, you're telling the JavaScript engine to enforce a stricter set of rules. It basically eliminates some potentially problematic or error prone parts of the language.
Pretty much. Yeah, yeah, key is the property name, value is the value. You access these values, usually with dot notation object dot property name, which is very common, right, Or you can use bracket notation object property name. That's handy when the property name is dynamic like stored in a variable, or maybe contains characters not allowed in dot notation.
Now there's an older array constructor, but Modissek advises against using it. It has this peculiar behavior. If you pass just a single number, oh yeah, instead of treating an array with that number in it, it creates an empty array with that specified length. So called sparse array can lead to some unexpected results down the line.
Yeah, it's a static method, really powerful. You can convert iterable objects like set, strings, even maps into proper arrays. It's also a neat way to create a shallow copy of an existing array. Okay, handy, And one key takeaway about JavaScript arrays is their flexibility. They can hold a mix of different data types. You can have numbers, strings, objects all in the same array.
Mighty Sick introduces them as patterns enclosed and forward slashes like pattern okay, and these can be followed by optional flags to modify their behavior, like g is for global matching finding all occurrences, not just the first one, and he makes the match case insensitive standard flags. Yeah. A key concept within rejecks is capturing groups. You create these by putting parts of the pattern in parentheses right to.
These groups are numbered from left to right, starting with one. Group zero usually represents the entire match, and these captured groups are incredibly useful. For instance, in a string's replace method, you can use one dollar, two dollars, et cetera in your replacement string to refer back to whatever those groups captured.
With G yep. Then there's match all pattern, which, especially with a G flag, returns an iterator of all matches. Really handy for four of flups and split regixt divides a string into an array of substrings using the rejects pattern as the delimitter. Plus there are methods directly on the rigix object itself, like exec string, which finds an next match in tracks position, and test ring, which is simpler, just returns true or false if there's a match.
JavaScript offers a pretty familiar set arithmetic plus kein ivelo percent, remainder and exponentiation, boolean logic andy andy and di enda nuts fame comparisons any dotic loose inequality, US strict inequality, string concatenation uses plus rocks, assignment operators plus and so on, the usual shorthand unary plus and ddea, and the ternary operator condition value false value false for concise conditionals.
Understanding the difference between in at and endear. This is huge in JavaScript, at least versus strict right. The loose equality attempts type coercion. It tries to convert operands of different types before comparing them. This leads to some surprising, often undesirable results like undefined null is actually.
Again, if you're coming from Java or C plus plus wave, much of JavaScript's statement syntax will feel very familiar. You have standard variable assignments, expressions used for side effects like function calls, blocks of code grouped by curly braces to define scope, and the usual control flow e false for conditions while up and double loops, and the four loop for iteration. Okay, one small detail. The initialization part of a for loop in modern JavaScript typically uses lead to declare the loop, counter scoping it nicely to just the loop. Good practice, and JavaScript switch statement is maybe a bit more flexible the case. Clauses can evaluate expressions, not just constant values, so.
The property names or keys of an object. Yeah, you can use it with user defined objects. A raise where it iterates index names as strings. Even strings iterating indices, but be aware it iterates over inherited innumerable properties too, and it might skip missing elements and sparse arrays. So it has its uses, But Forurian is often preferred for iterating values in collections.
That's where the tricatch finally block comes in code that my throw goes in the try block. Standard If an exception happens, control jumps to the catch block. You can have an optional variable in catch to hold the throne value. Okay, and the finally block, if you include it, always executes after trying cash whether an exception occurred or not. Great for cleanup makes sense. An interesting quirk If try or catch has a return, break or continue, its execution is sort of paused until the finally block finishes.
Writing and running tests, often within a browser. For client side code. He outlines the basic structure describe blocks to group tests, it blocks for individual test cases with descriptive names inside it. Use assertions from Chi's assert object to check if your code behaves as expected. He shows examples like assert dot is true, assert dot is false, assert dot equal for loose equality.
You can pull out specific properties or elements. You can even rename properties during extraction, like let username nice, and you can provide default values if a property might be missing nice. It's especially powerful in function parameter lists. You can destructure an object passed as an argument right in the parameter definition.
Yes, numbers again reiterated. They're mostly sixty four bit i ee seven hundred and fifty four floats except for bigot. He mentions the special values infinity, infinity, and nan not a number right nan, and the is finite function to check for actual finite numbers. Also useful constants like number dot mn value, number dot x value and number dot epsilon that tiny difference.
He mentions unshift and shift for adding removing from the beginning, but notes they can be less efficient than push pop. At the end, he also highlights Han's own property. It's a reliable way to check if an object, including an array actually has a property directly on itself, not inherited, and useful for distinguishing real elements from undefined slots in sparse arrays. Such JavaScript doesn't have built in methods for standard set operations like union, intersection, difference. Oh really yeah, but metwusex shows how you can implement them yourself, using the spread syntax to convert sets to arrays and then using array methods like filter along with the sets as method.
He stresses using parentheses when mixing with milan or due to precedence rules. As for bad operators, he references Crockford's JavaScript The good parts. For instance, the prefixed postfix increment, plus plus and decrement operators are sometimes discouraged. Why is that they can make code less clear, especially when used inside complex expressions. Using plus one or nakeld one is often more explicit and less aero prone.
Definitely several ways to define them. The standard function declaration function expressions. Assigning function to a variable can be anonymous or named. The function constructor takes code as strings. Generally bad idea right, avoid that one and erow functions which have concise syntax and crucially lexical this binding.
Generators are special functions that can pause and resume. Defined with function calling one doesn't run it, but returns a generator object, which is an iterator inside the yield keyword returns a value and pauses execution. Calling next on the generator object resumes it until the next yield or the end, and next returns an object like the yielded value done false. When the generator finishes, reaches an end or hits a return, next returns value final value or undefined done through. Once done, it's done, can't restart it, Nope. They're great for creating custom iterators easily. He shows a simple half end generator example.
An object is iterable if it implements the iterable protocol. That means having a method keyed by the special symbol symbol dot iterator. This method must return an iterator object which has a next method. Often the easiest way to implement symble dot iterator is just to make it a generator function. Mitisek shows an example making an object with start, step and iterable using a generator.
Yeah. If you have a variable let make toyota and want an object make toyota, you just write that make nice shortcut cool. Checking for properties, the in operator checks if a property exists, including inherited ones. Fore end loops over innumerable property names including inherited okay. Creating objects literals, object adding properties dynamically, constructor functions with new using this inside yeah and object dot create prototype, which creates a new object with a specific prototype you provide.
Its value is determined by how a function is called, the call site evaluated at run time. Inside a method called like UBJ dot method, this is usually object. In a constructor called with new, this is the new object being created. Makes sense in a regular function called directly, not as a method in non strict mode, this is the global object window and browsers, but in strict mode it's undefined.
Yes, and a function inside another function. This inside the inner one follows the regular function rules. It doesn't automatically inherit the outer this unless unless it's an erowfunction. Erofunctions capture this value from their surrounding lexical scope. They don't have their own this binding.
Every JavaScript object has an internal link to another object, its prototype. You can get it with object dot get prototype. When you access a property, If the object doesn't have it directly, JavaScript looks at its prototype. If it's not there, it looks at the prototypes prototype, and so on up the chain.
Classes from e S twenty fifteen are mostly syntactic sugar over the existing prototype based inheritance. They provide a clear or more familiar syntax from many programmers, a blueprint kind of my class constructor. Defining a class essentially creates a constructor function and adds methods to its prototype property new my class calls the constructor this inside refers to the instance, and inheritance uses the extends keyword. Class subclass extends superclass. The subclass prototype is linked to the superclass prototype inheriting methods. You can override methods if no extends it implicitly extends object.
Yes, The my class dot prototype object holds the method definition shared by all instances. You can still add methods directly to my class dot prototype after the class definition and all instances will get it. Object prototype of instance still works. Object I creates still works. The underlying mechanism.
Two main tools, transpilers and polyfills. Transpilers like Babble convert newer syntax hegany aerofunctions classes into older compatible syntax. Polyfills are pieces of code that provide implementations for features missing in older environments, like if a browser doesn't have the raate oup prototype dot includes method, you can include a polyfil that adds it.
The rest of the book focuses on guys and the browser and using the DOM to interact with the page. It starts with some essential HTML review right the structure HML page is a text file with tags container tags, tag content tag, empty tags like BR basic structure doctri type HDL HTML head with title body. Tags can have attributes name value like AID HTML tags attributes are case in sensitive, but JS is case sensitive, CSS handles is styling and.
Yes, especially for larger scripts. You can also use evan handler attributes like on click JS code directly on HTML elements, though separating JS is often cleaner. Function definitions best in head, scripts and body execute as the page loads. NoScript provides fallback content if JS is off.
Input type text can set size for a visible width value for initial text. To get user input, find the element again by ID and read its dot value property in JavaScript simple enough? How do HTML forms fit in form acts as a container for related inputs, usually for submitting data. Submit buttons type submit, trigger, submission, reset buttons type reset clear the form plain buttons type button do nothing by default. A button inside a form default to type submit if unspecified. Okay forms define a scope for the name attribute on inputs. This name identifies the data when submitted. I must be unique on the whole page. Forms can't be nested. Pressing it entering an input field often submits the form if there's a submit put.
Input type radio used in groups with the same name. Selecting one d selects others in the group. Input type checkdocs are independent selections others. Input type image src images, submit button, input type color colorpicker, input type hidden data smitted but not visible, input type range slider.
Events are actions user clicks, keypresses, pageloads handled by attributes like on click JS code. Event names are a lowercase in HTML attributes on click often CamelCase and JS on click common events dot onload onload for bodyframes, mouse dot on, click on, be able to click on mouse down on mouse up on mouseover on mouse out on mass move, pointer events on pointer out, unify, mouse touch, focus, dot on, focus on, blur, change on, change on select form, dot on, reset on submit return false, camp image, dot on a board on error, keyboard dot donkey down on keypress, event dot key on KIAP.
User interaction, dot alert, proft, confirmed timers, dot delay runs funk once after delay milliseconds, set interval, fagigible runs funk repeatedly every interval milliseconds. Both return IDs to use with clear timeout or clear interval to stop them. My two sex shows using set timeout with window dot location for a time to redirect.
Use methods on the parentode where you want to add it. Parentode dot penchild child node adds it at the end. Parentnode dot insert before new nodes. Existing node inserts before another child parentnode dot remove child noode removes it parentode dot replaced child new noode. Old nodes swaps one for another.
Elements have element dot tag name oopcase element dot inner HTML get sets the HTML content inside the element element dot or HTML get sets the elements full HTML, including its own tags. Element dot attributes is a collection of attribute nodes. Element dot class name is the string of classes. Element dot class list is better a list object with ad remove toggle contains methods for classes. Element dot style accesses inline styles.
They have their own get elements by class name, querity selector query selectoral that search only within that element's descendants. Also element dot, get attribute, element dot or room attribute, and element dot insert adjacent HTML where htmail inserts HTML strings relative to the element before begin after begin before whatever.
Well that brings us towards the end of this deep dive. My key takeaway from quick JavaScript is its effectiveness for experienced programmers needing a fast, targeted intro to JS and the DOM. But you absolutely have to understand its scope, who it's for, and what it deliberately leaves out.
And a final thought to leave you with, think about JavaScript's journey. A language often described as being maybe hastily put together initially has become this absolute powerhouse driving modern web experiences. What does that evolution tell us about the balance between say, initial design perfection versus continuous adaptation and community driven growth and technology Something to ponder. Thanks for joining us on this deep dive.
