Today I Learned - Rocky Kev

Tagged “mdn”

  1. TIL fancy methods to transform Javascript Objects

    You can use Object.entries(), Object.keys(), Object.fromEntries()...

  2. TIL How to steal localData using an XSS attack

    But that's just a red flag that opens the door to bigger issues.

  3. TIL Clear-Site-Data

    The Clear-Site-Data header clears browsing data (cookies, storage, cache) associated with the requesting website. It allows web developers to have more control over the data stored by a client browser for their origins.

  4. TIL using abortController to removing events

    Trying to unhook a eventListener? Don't use `removeEventListener`, instead use AbortController.

  5. TIL detecting if a user is online with JS

    You can use the navigator.onLine api.

  6. TIL Tagged Templates

    Tags allow you to parse template literals with a function. The first argument of a tag function contains an array of string values. The remaining arguments are related to the expressions.

  7. TIL wanting to use the latest thing

    In evaluating a solution, be sure to consider the library dying out or becoming a maintenance burden after 5 years (e.g., everyone trying to get off jQuery onto Web Components).

  8. TIL Computed Properties in Javascript

    Today I learned about Computed Property names.

  9. TIL AggregateError

    I heard the term AggregateError in relations to 'Promise.Any', So it's several errors wrapped in a array. That's all.

  10. TIL safe areas for mobile browsers

    The problem you quickly encounter is that the visible viewport is not per se the same as the interactive viewport. Mobile browsers tend to prioritize essential UI elements (like the home-bar on IOS) for interactivity at all times.

  11. TIL that the max size of a Map/Set is 26843544

    JS Maps and Sets are implemented by OrderedHashTable. OrderedHashTables double in size when they need to grow, and their max size is 26843544. After 16777216 elements, doubling that exceeds the max, so the allocation fails.Currently these data structures are not implemented to be usable for large in-memory datasets. Also note that the JS specification itself doesn't require that Maps and Sets must scale with available memory.

  12. TIL that adding a psuedo-h7

    Natively, there are 6 heading levels. What if accessibility-wise, you wanted a new heading level?

  13. TIL super()

    When you use super(), it's like you're telling the new object to copy everything from the old object first, and then add or change anything else that's different.

  14. TIL switching over to Service Workers with Chrome extensions

    Background Pages are like 'hidden pages' that a developer would create behind the scenes. That hidden page would do various JS needs to simulate functionality. Vs a service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page or user interaction

  15. TIL using defer/async

    So an old and often-touted best practice for performance has been to load your JavaScript in the footer of the document to avoid render blocking of scripts. By putting it in the footer, the DOM is constructed before your scripts have a chance to run. That's dumb.

  16. TIL about console.dir

    If you console.log a element, you will get it's HTML markup. If you want it as a JS object, use console.dir instead

  17. TIL Replace Only Fixes the First Encounter

    Replace only finds the first occurrence. ReplaceAll fixes it all.

  18. TIL use-cases for Generators in Javascript

    Generators are functions that can be exited and later re-entered. Their context (variable bindings) will be saved across re-entrances.

  19. TIL Number formatting with Javascript

    Say you wanted to convert this into a string, with all the commas and everything. You can use the browser Intl package to use this.

  20. TIL refactoring object lookups to avoid looking at the prototype chain

    Depending on your lookup method, you can access the prototype chain, which opens up some potential vulnerabilities or terrible side effects!

  21. TIL about heavy.js

    It downscales all images on your webpage by a factor of 3, takes the RGB values and creates spans with appropriate styles. Yes, this converts your images to HTML p and spans.

  22. TIL cancelling promises

    There is a cross-platform (Node, Browsers, etc) cancellation primitive called AbortController. You can use it to cancel functions that return promises rather than promises themselves.

  23. TIL the WebCrypto API

    If you dealing with sensitive applications and need a more secure method of randomization, I’d recommend the Crypto API. Reasons you may want to use WebCrypto include temporary verification codes, random password generation, randomized lottery numbers, etc.

  24. TIL ES6 Proxy's apply method

    Using JavaScript proxies you can wrap an existing object and intercept access to its attributes or methods, even if they don’t exist. You can also redefine fundamental operations for that object.

  25. TIL ES6 Proxy

    Using JavaScript proxies you can wrap an existing object and intercept access to its attributes or methods, even if they don’t exist. You can also redefine fundamental operations for that object.

  26. TIL about the Clipboard API

    The Clipboard API can be used to implement cut, copy, and paste features within a web application.

  27. TIL the wbr element

    '<wbr>' is a HTML element that represents a word break opportunity—a position within text where the browser may optionally break a line, though its line-breaking rules would not otherwise create a break at that location.

  28. TIL a short explainer of the Execution Context

    It is an abstract concept that represents the environment in which JavaScript runs. What happens inside the execution context is two things basically. The first is parsing the code line by line and the second is storing the variables and functions into the memory.

  29. TIL onError

    When a resource (such as an img or script) fails to load, an error event using interface Event is fired at the element that initiated the load, and the onerror() handler on the element is invoked.

  30. TIL addEventListener's third param

    The mysterious useCapture and options.

  31. TIL add link decoration to help with accessibility

    One of the WCAG requirements is not to rely on color only when you want to distinguish a button or link from the rest of the text. Painting links in blue or another color doesn’t suffice since it still might not be visible for people with color blindness. The most typical method is underlining links; they can also appear in bold font.

  32. TIL the global attribute translate

    A good use-case is if your brand has words that can be translated.

  33. TIL default spellcheck in html

    The spellcheck is a global attribute that you can use to check spelling and grammar on HTML elements such as input fields and other editable elements.

  34. TIL the multiple value in html

    The multiple attribute allows the user to enter multiple values on an '<input>'. It is a boolean attribute valid for file or email input types and the '<select>' element.

  35. TIL of the base element

    base element adds the domain link to all relative links.

  36. TIL you can make SMS links

    So you can make a 'mailto:' and a 'tel:' link. But did you know you can also do 'sms' messages too?

  37. TIL how to make numbers the same width and prevent shifting layout

    If your font supports it, you can use 'font-variant-numeric: tabular-nums'.

  38. TIL using datalist for a pure HTML input suggestion

    Web developers do not use the power of 'datalists' enough. It combines the power of a 'selector', with the ability to type out your choice using the keyboard.

  39. TIL how to set up autogrowing textarea fields

    There's some css tricks to autogrow textarea. There's also a nice piece of JS to use to do it as well!

  40. TIL of the selectopt group

    You can create some cool dividers for your field options using the 'optgroup' element.

  41. TIL of using the "is" property

    The ':is()' CSS pseudo-class function takes a selector list as its argument, and selects any element that can be selected by one of the selectors in that list.

  42. TIL of a visual way to see CSS Cascade

    But then questions start arising: is !important higher priority than say, the Shadow DOM generated object?

  43. TIL how to replace many characters in javascript

    You can use the replace() method to swap one string pattern for another.

  44. TIL about the battery status API

    Do you want to know all about the battery of your laptop, PC or, devices? This API helps in knowing all the information like, the battery is charging or not, how much charge is left and also the handlers to handle the charge related state changes.

  45. TIL how to pass unlimited arguments to a function

    The rest parameter syntax allows a function to accept an indefinite number of arguments as an array, providing a way to represent variadic functions in JavaScript.

  46. TIL how to get the location of the user with the Geolocation API

    You can get the user's location in the browser. First, the user has to accept this. As it's a security request. Second, you use the Geolocation API.

  47. TIL about the new Intl.NumberFormat browser API

    No more stupid-ass hacks to format numbers correctly.

  48. TIL trailing commas in Javascript

    JavaScript has allowed trailing commas in array literals since the beginning, and later added them to object literals, and more recently, to function parameters and to named imports and named exports.

  49. TIL startWith

    Getting a boolean result of true or false, depending on if the string startsWith a specific substring

  50. TIL a quick recipe involving Axios and Cheerio

    A quick recipe to http request an api and use cheerio to web-scrape it

  51. TIL that keyCode is depreciated

    KeyboardEvent.keyCode is depreciated. Because it was inconsistent. Use a the code version instead, it's more readable.

  52. TIL writing modes

    The 'writing-mode' CSS property determines if lines are laid our horizontally, or vertically. The direction is determined by the context of the direction of the content.

  53. TIL the hover media feature

    If you're on a phone or tablet, chances are -- you cannot hover. But if you're on desktop using a mouse -- you can!

  54. TIL You can change the blinking line

    The caret-color CSS property sets the color of the insertion caret, the visible marker where the next character typed will be inserted. This is sometimes referred to as the text input cursor.

  55. TIL how to get a random Hex color

    Math.random()*16777215 then turn it into a

  56. TIL Value as Number

    Returns the value of the element, interpreted as one of the following, in order: A time value, A number, NaN if conversion is impossible.

  57. TIL toLocaleDateString that's built into Javascript for dates

    Date().toLocaleDateString('en-US') returns a string with a language sensitive representation of the date portion of this date.

  58. TIL LocalForage, a small js library for caching

    An easy to use library to help with web storage. Switches between localStorage/sessionStorage, and also IndexedDB automagically. 178,000 repos can't be wrong.

  59. TIL super keyword in Javascript classes

    the super keyword is mainly used when we want to access a variable, method, or constructor in the base class from the derived class.

  60. TIL about Constraint Validation API (forms)

    Inputs are pretty powerful. Right out of the box, they can autocomplete, validate data, create minimum/maximum lengths, allow for patterns, and even provide state!

  61. TIL HTML elements like Blockquote, datalist, details, meter, & progress

    HTML Elements I forget exist. Blockquote, datalist, details, meter, progress

  62. TIL column gap for newspaper look

    Use `column-count` and `column-gap` to give it that sweet newspaper look.

  63. TIL Web Speech API

    Have multiple cursors

See all tags.