<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Atta 🐬</title>
    <description>The latest articles on DEV Community by Atta 🐬 (@attacomsian).</description>
    <link>https://dev.to/attacomsian</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F93443%2F616af616-e8f3-4132-adb5-d185bd5f3528.jpg</url>
      <title>DEV Community: Atta 🐬</title>
      <link>https://dev.to/attacomsian</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/attacomsian"/>
    <language>en</language>
    <item>
      <title>How to Sell a Mac App Outside the App Store (2026)</title>
      <dc:creator>Atta 🐬</dc:creator>
      <pubDate>Thu, 03 Dec 2026 12:52:11 +0000</pubDate>
      <link>https://dev.to/attacomsian/how-to-sell-a-mac-app-outside-the-app-store-2026-5fcn</link>
      <guid>https://dev.to/attacomsian/how-to-sell-a-mac-app-outside-the-app-store-2026-5fcn</guid>
      <description>&lt;p&gt;I sell &lt;a href="https://vitalsmac.com" rel="noopener noreferrer"&gt;Vitals&lt;/a&gt; on its own site. The Mac App Store needs every app to run in a sandbox, and the sandbox stops an app from seeing other apps' processes. Vitals is an activity monitor, so the App Store was never an option.&lt;/p&gt;

&lt;p&gt;Selling it myself has gone well. Vitals came out on September 24, and 1,514 orders came in during its first month, all through my own site. But I had to set up everything the App Store does for you. That means payments, sales tax, license keys, a trial, and updates.&lt;/p&gt;

&lt;p&gt;Here's what each one takes, in the order I'd do them, and what I use for Vitals.&lt;/p&gt;

&lt;h2&gt;
  
  
  App Store or your own site
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Mac App Store&lt;/th&gt;
&lt;th&gt;Your own site&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Fee&lt;/td&gt;
&lt;td&gt;15% in Apple's Small Business Program, 30% otherwise&lt;/td&gt;
&lt;td&gt;3.9% to 5%, plus 40¢ to 50¢ a sale&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sandbox&lt;/td&gt;
&lt;td&gt;Required&lt;/td&gt;
&lt;td&gt;Up to you&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sales tax and VAT&lt;/td&gt;
&lt;td&gt;Apple pays it&lt;/td&gt;
&lt;td&gt;The store that sells your app pays it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Free trial&lt;/td&gt;
&lt;td&gt;Through an in-app purchase&lt;/td&gt;
&lt;td&gt;Any way you like&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Updates&lt;/td&gt;
&lt;td&gt;After App Review&lt;/td&gt;
&lt;td&gt;The day you ship them&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Buyers' emails&lt;/td&gt;
&lt;td&gt;Apple keeps them&lt;/td&gt;
&lt;td&gt;You get them&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Being found&lt;/td&gt;
&lt;td&gt;App Store search&lt;/td&gt;
&lt;td&gt;Up to you&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The last row is the big one. On your own site, nobody finds the app unless you bring them there.&lt;/p&gt;

&lt;p&gt;You don't have to pick one. Some developers sell a sandboxed version on the App Store and a full version on their own site.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Sign and notarize your app
&lt;/h2&gt;

&lt;p&gt;Since macOS Sequoia, a Control-click no longer opens an app that isn't notarized. People have to go to System Settings › Privacy &amp;amp; Security and click Open Anyway, and many give up before they get there. So this comes first.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Join the Apple Developer Program, which is $99 a year. I wrote about &lt;a href="https://macbase.app/blog/is-apple-developer-program-worth-it" rel="noopener noreferrer"&gt;what else it includes&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Sign your app with a Developer ID Application certificate, with the hardened runtime turned on.&lt;/li&gt;
&lt;li&gt;Send it to Apple: &lt;code&gt;xcrun notarytool submit YourApp.dmg --keychain-profile notary --wait&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Staple Apple's ticket to it, so it opens even when the Mac is offline: &lt;code&gt;xcrun stapler staple YourApp.dmg&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Apple usually answers in a few minutes. Once it's stapled, your app opens with the usual "downloaded from the internet" prompt and nothing scarier.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Pick a store that pays sales tax for you
&lt;/h2&gt;

&lt;p&gt;When you sell software, you owe sales tax, VAT, or GST in every country your buyers live in. A merchant of record sells your app on your behalf. It charges the buyer, pays the tax, handles refunds and chargebacks, and sends you the rest.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Store&lt;/th&gt;
&lt;th&gt;Fee per sale&lt;/th&gt;
&lt;th&gt;License keys&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://www.paddle.com" rel="noopener noreferrer"&gt;Paddle&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;5% + 50¢&lt;/td&gt;
&lt;td&gt;Not included&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://www.creem.io" rel="noopener noreferrer"&gt;Creem&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;3.9% + 40¢&lt;/td&gt;
&lt;td&gt;Included&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://polar.sh" rel="noopener noreferrer"&gt;Polar&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;5% + 50¢ on the free plan, less on paid plans&lt;/td&gt;
&lt;td&gt;Included&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://gumroad.com" rel="noopener noreferrer"&gt;Gumroad&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;10% + 50¢&lt;/td&gt;
&lt;td&gt;Included&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://stripe.com" rel="noopener noreferrer"&gt;Stripe Managed Payments&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;3.5%, plus Stripe's card fees&lt;/td&gt;
&lt;td&gt;Not included&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I use Paddle for Vitals. It shows each buyer the price in their own currency, and its checkout opens on top of my pricing page, so nobody leaves the site to pay.&lt;/p&gt;

&lt;p&gt;Creem takes the least per sale of these five. It also creates a license key with each sale, so you don't have to build your own, and it has no monthly fee.&lt;/p&gt;

&lt;p&gt;If you use Lemon Squeezy, it stopped taking new sellers on November 16, 2026, and it stops taking payments on March 31, 2027. Stripe owns it and points sellers to Stripe Managed Payments, which doesn't issue license keys. So plan your move early.&lt;/p&gt;

&lt;p&gt;On a cheap app, the fixed part of the fee matters more than the percentage. At $5, Paddle takes 75¢. That's 15%, the same as the App Store's small business rate. Creem takes about 60¢. At $49, Paddle takes $2.95, about 6%.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Add license keys
&lt;/h2&gt;

&lt;p&gt;Your app needs a way to know who paid. Creem, Polar, and Gumroad create a key with each sale and let your app check it. Paddle doesn't, so you need a licensing service or a server of your own.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://keylight.dev" rel="noopener noreferrer"&gt;Keylight&lt;/a&gt; is a licensing service made with Mac apps in mind, and it costs much less than the older options. It's free for up to 25 active licenses, and $19 a month for up to 2,000 Macs. It has a Swift package, checks keys even when the Mac is offline, and works with Stripe directly and with stores like Paddle through a webhook. &lt;a href="https://keygen.sh" rel="noopener noreferrer"&gt;Keygen&lt;/a&gt; has been around longer, has more settings, and has a version you can host yourself.&lt;/p&gt;

&lt;p&gt;For Vitals, I built my own. Paddle handles the money, and my server handles the licenses. When someone pays, Paddle tells my server, and the buyer gets a key by email. They paste it into Vitals once on each Mac. Vitals checks it once a week. There's no account to make.&lt;/p&gt;

&lt;p&gt;Because the server is mine, one key now works in all four of my apps at &lt;a href="https://fore.studio" rel="noopener noreferrer"&gt;Fore Studio&lt;/a&gt;. That's how I sell them as a bundle.&lt;/p&gt;

&lt;p&gt;Each key works on as many Macs as it was bought for. When someone gets a new Mac, they free the old one in Vitals' Settings or on a web page, without writing to me.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Offer a free trial
&lt;/h2&gt;

&lt;p&gt;Someone who finds your app on your site has no reviews or ratings to go on. A trial lets them see it working on their own Mac before they pay.&lt;/p&gt;

&lt;p&gt;Vitals has a &lt;a href="https://vitalsmac.com/download" rel="noopener noreferrer"&gt;3-day trial&lt;/a&gt; with every feature, and no account or card. You open the app and choose Try Free. Don't ask for an email or a card before the trial starts.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Ship updates with Sparkle
&lt;/h2&gt;

&lt;p&gt;Outside the App Store, your app has to update itself. &lt;a href="https://sparkle-project.org" rel="noopener noreferrer"&gt;Sparkle&lt;/a&gt; is the open-source framework most Mac apps sold outside the App Store use for that.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add Sparkle to your project with Swift Package Manager.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;generate_keys&lt;/code&gt; once. It keeps a private key in your keychain and prints a public key, which goes in your app's &lt;code&gt;SUPublicEDKey&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Put the address of your update feed, called an appcast, in &lt;code&gt;SUFeedURL&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For each release, run &lt;code&gt;generate_appcast&lt;/code&gt; on the folder with your DMGs. It signs every update and writes the feed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Vitals has had &lt;a href="https://vitalsmac.com/changelog" rel="noopener noreferrer"&gt;more than 80 updates&lt;/a&gt; since launch. Each one reached people the day I shipped it, with no review to wait for.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Price it
&lt;/h2&gt;

&lt;p&gt;On your own site, you can price an app any way you like. I sell Vitals two ways, both paid once. A lifetime license gets every update. A year of updates is $12, and the app keeps working after the year ends.&lt;/p&gt;

&lt;p&gt;I launched it at $5 for the first 1,000 licenses. Then the price went up in steps as they sold: $9 for the next 450, $15 for the next 50, and $19 for 35 more. The &lt;a href="https://vitalsmac.com/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt; showed how many were left at each price, counted from the sales themselves. The first 1,000 sold in eight days, almost all from my posts on X. Vitals is $12.99 right now, and its regular price is $49.&lt;/p&gt;

&lt;p&gt;One step went wrong. After $15, I set the price to $29 for a day and a half. It should have been $19, so I went back to it. Keep the steps small, so nobody feels they missed out by a day.&lt;/p&gt;

&lt;p&gt;If people want your app on more than one Mac, sell packs. A Vitals pack never costs more for each Mac than a single license.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Make it easy to install
&lt;/h2&gt;

&lt;p&gt;Ship a DMG that people drag to Applications, and add a &lt;a href="https://brew.sh" rel="noopener noreferrer"&gt;Homebrew&lt;/a&gt; cask. Many developers install their apps that way, and updating is one command.&lt;/p&gt;

&lt;p&gt;The main Homebrew cask list has rules about how well known an app must be, so start with a tap of your own. Vitals installs with &lt;code&gt;brew install --cask foredotstudio/tap/vitals&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Refunds and support
&lt;/h2&gt;

&lt;p&gt;Vitals has a 14-day refund. A refund is one click in Paddle. Paddle returns the money to the buyer and takes it out of my next payout, so I never handle a payment myself.&lt;/p&gt;

&lt;p&gt;Put your support email in the app and on every page. Your buyers can't go to Apple for help, so they'll write to you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where buyers come from
&lt;/h2&gt;

&lt;p&gt;Without App Store search, you bring every buyer yourself. For Vitals, that was X first, then Show HN, Product Hunt, and sites that wrote about it, like sspai in China and MacMagazine in Brazil. I put the whole list in &lt;a href="https://macbase.app/blog/best-places-to-promote-your-mac-app" rel="noopener noreferrer"&gt;23 Best Places to Promote Your Mac App&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Can I sell a Mac app without the App Store?
&lt;/h3&gt;

&lt;p&gt;Yes. Sign it with a Developer ID, notarize it, and sell it through a merchant of record like Paddle, Creem, Polar, or Gumroad. Add license keys, a free trial, and Sparkle for updates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need to notarize my Mac app?
&lt;/h3&gt;

&lt;p&gt;Yes, if you want it to open without a warning. Since macOS Sequoia, a Control-click no longer opens an app that isn't notarized. People have to allow it in System Settings › Privacy &amp;amp; Security.&lt;/p&gt;

&lt;h3&gt;
  
  
  What does it cost to sell a Mac app on my own site?
&lt;/h3&gt;

&lt;p&gt;The Apple Developer Program is $99 a year. Creem takes 3.9% + 40¢ a sale. Paddle takes 5% + 50¢, and so does Polar's free plan. All three pay sales tax and VAT for you. Gumroad takes 10% + 50¢. On the App Store, Apple takes 15% in its Small Business Program and 30% otherwise.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I add license keys to a Mac app?
&lt;/h3&gt;

&lt;p&gt;Sell through a store that creates them, like Creem, Polar, or Gumroad. Or use a licensing service like Keylight, which is free for up to 25 active licenses and $19 a month for up to 2,000 Macs, or Keygen. You can also run a licensing server of your own, which is what I do for Vitals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is Lemon Squeezy still an option for Mac apps?
&lt;/h3&gt;

&lt;p&gt;Not for new apps. Lemon Squeezy stopped taking new sellers on November 16, 2026, and stops taking payments on March 31, 2027. Stripe points its sellers to Stripe Managed Payments, which doesn't issue license keys. Creem, Polar, and Gumroad all include license keys.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I sell my Mac app on the App Store and my own site?
&lt;/h3&gt;

&lt;p&gt;Yes. Many developers sell a sandboxed version on the Mac App Store and a full version on their own site, each with its own price.&lt;/p&gt;

&lt;p&gt;If you sell a Mac app, &lt;a href="https://macbase.app/submit" rel="noopener noreferrer"&gt;list it on MacBase&lt;/a&gt; for free. It gets a page, a link to your site, and a place in its category.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I’m Atta. I make Mac apps at &lt;a href="https://fore.studio" rel="noopener noreferrer"&gt;Fore Studio&lt;/a&gt; that you pay for once, including Vitals, Levers, SoundBar, and Flit, and I write about building and selling them. Follow me on X at &lt;a href="https://x.com/attacomsian" rel="noopener noreferrer"&gt;@attacomsian&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>macos</category>
      <category>swift</category>
      <category>startup</category>
      <category>indiehackers</category>
    </item>
    <item>
      <title>10 Mac Apps I’d Actually Pay for This Cyber Monday</title>
      <dc:creator>Atta 🐬</dc:creator>
      <pubDate>Mon, 30 Nov 2026 15:45:37 +0000</pubDate>
      <link>https://dev.to/attacomsian/10-mac-apps-id-actually-pay-for-this-cyber-monday-2b6a</link>
      <guid>https://dev.to/attacomsian/10-mac-apps-id-actually-pay-for-this-cyber-monday-2b6a</guid>
      <description>&lt;p&gt;Most Mac apps worth paying for cost the same all year. Cyber Monday is one of the few days that isn’t true, and a lot of indie developers run their only sale of the year around it.&lt;/p&gt;

&lt;p&gt;The hard part is telling a good deal from a loud one. Plenty of Cyber Monday “deals” are a subscription with a cheap first month, or the usual price with a bigger badge.&lt;/p&gt;

&lt;p&gt;So I kept this list to apps a regular Mac user would install, and most of them you pay for once. Four are apps I make at &lt;a href="https://fore.studio" rel="noopener noreferrer"&gt;Fore Studio&lt;/a&gt;. The other six are from indie developers whose deals I found on &lt;a href="https://macbase.app/deals" rel="noopener noreferrer"&gt;MacBase&lt;/a&gt;, the Mac app directory I run.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Vitals
&lt;/h2&gt;

&lt;p&gt;I build a system monitor, so I spend a lot of time in Activity Monitor. When my Mac slows down, it lists hundreds of processes, and most of them have names nobody recognizes. It never tells me which app is behind the slowdown.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vitalsmac.com" rel="noopener noreferrer"&gt;Vitals&lt;/a&gt; adds those processes up into the apps they belong to. Chrome shows up as one row with all its helpers counted, not as a long list of Google Chrome Helper processes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn7zu9h642aqu6gjtap63.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn7zu9h642aqu6gjtap63.png" alt="Vitals showing CPU over the last hour, with Terminal, Xcode, and Google Chrome at the top of its list" width="800" height="500"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Vitals, with each app’s CPU over the last hour&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Each app shows its CPU, memory, energy, disk, and network use, with up to a year of history. So you can go back and see what was running when your fans spun up yesterday afternoon. In the menu bar, Vitals keeps CPU, memory, temperature, fans, and battery one click away.&lt;/p&gt;

&lt;p&gt;Vitals has sold more than 2,000 copies so far. For Cyber Monday, a lifetime license is $12.99 instead of $49. There’s a 3-day free trial, and it needs macOS 15.&lt;/p&gt;

&lt;p&gt;If your Mac feels slow and Activity Monitor doesn’t tell you why, this is the one to get.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. SoundBar
&lt;/h2&gt;

&lt;p&gt;macOS still has one volume slider for every app. Turn the music down for a call, and the call goes down with it.&lt;/p&gt;

&lt;p&gt;I made &lt;a href="https://soundbarmac.com" rel="noopener noreferrer"&gt;SoundBar&lt;/a&gt; to fix that. Every app that plays sound gets its own slider, from 0 to 200%, and the mixer opens from the MacBook’s notch. On a Mac without a notch, it opens from the menu bar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flggv2zqmjfna9wt5vdf1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flggv2zqmjfna9wt5vdf1.png" alt="SoundBar’s mixer with volume sliders for Music, Safari, Zoom, Brave, and Slack, and an equalizer for Music" width="800" height="500"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;SoundBar’s mixer, with an equalizer open for Music&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Each app can have its own equalizer and its own output, too. Music can play on the speakers while a call goes to your AirPods. When an app starts using the microphone, the others fade down, and every app keeps its settings between launches.&lt;/p&gt;

&lt;p&gt;A lifetime license is $6.99 for Cyber Monday instead of $29, with a 3-day free trial. It needs macOS 15.&lt;/p&gt;

&lt;p&gt;SoundBar is for anyone who takes calls while music or a video is playing.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Levers
&lt;/h2&gt;

&lt;p&gt;The settings I change most are a few clicks deep in System Settings, like Keep Awake, Dark Mode, hiding the Dock, and showing hidden files. &lt;a href="https://leversmac.com" rel="noopener noreferrer"&gt;Levers&lt;/a&gt; puts 68 of them in the menu bar, one click each.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz3zu86yfrgimqenb7ehk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz3zu86yfrgimqenb7ehk.png" alt="Levers’ switches in the menu bar, with Dark Mode, Hide Dock, and Keep Awake on a two-hour timer" width="800" height="500"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Levers in the menu bar, keeping the Mac awake for two hours&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Any switch can have a hotkey and an off timer, so you can keep your Mac awake for two hours and let it sleep after that. Modes flip several switches at once for a call, a presentation, or focused work. They can turn on by themselves at a set time, when an app opens, or when you share your screen.&lt;/p&gt;

&lt;p&gt;It tidies the menu bar now, too. Levers hides the icons you don’t need on shelves that come back when you point at the bar, and you can open any of them from the keyboard. The latest update added a timer, a stopwatch, Pomodoro rounds, and ambient sounds to work to.&lt;/p&gt;

&lt;p&gt;Recording Mode is the one I’d point out. When a call or a recorder captures your screen, it hides your desktop files, the Dock, and other apps. It puts everything back when the recording stops.&lt;/p&gt;

&lt;p&gt;For Cyber Monday, a lifetime license is $6.99 instead of $29, with a 3-day free trial. It needs macOS 15.&lt;/p&gt;

&lt;p&gt;If your menu bar is crowded or you open System Settings more than once a day, Levers is the one to get.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Flit
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://flit.fyi" rel="noopener noreferrer"&gt;Flit&lt;/a&gt; is the dictation app I make. Hold a key, talk, and let go, and the text lands wherever your cursor is. The ums and false starts are gone, and numbers, dates, and links come out the way you’d type them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhxa9zy6w7a98pwluynbc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhxa9zy6w7a98pwluynbc.png" alt="Flit writing the same dictation three ways in Messages, Mail, and Notes" width="800" height="500"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Flit writing the same dictation three ways&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It runs on your Mac, with no account and no cloud, so it works offline. It learns the names and terms you use, and it can transcribe a meeting or a voice memo you drop into it.&lt;/p&gt;

&lt;p&gt;For Cyber Monday, it’s $15 once, 62% off its usual price. There’s a 7-day free trial, and it needs macOS 14.&lt;/p&gt;

&lt;p&gt;Flit is for anyone who writes a lot of messages, notes, or prompts and would rather say them.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. ActionClip
&lt;/h2&gt;

&lt;p&gt;On an iPhone, selecting text brings up a small menu of things to do with it. &lt;a href="https://actionclip.app" rel="noopener noreferrer"&gt;ActionClip&lt;/a&gt; brings that menu to the Mac.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9xli73fb3nz5qhjqzil8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9xli73fb3nz5qhjqzil8.png" alt="ActionClip’s menu over selected text, with Fix Grammar, Refine, Summarize, and Write Formally" width="800" height="500"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;ActionClip’s menu over selected text (image from ActionClip)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Select text in any app, and it shows the actions that fit it first. You can translate it, fix the grammar, summarize it, count the words, or convert a currency, a unit, or a time zone. Many of these work without AI. The ones that use AI can run on your Mac with Apple Intelligence or Ollama, or use your own key for Claude, ChatGPT, or Gemini. You can also make your own actions from a prompt, a script, or a shell command.&lt;/p&gt;

&lt;p&gt;It’s free for 30 actions a day. For Cyber Monday, lifetime plans for unlimited actions start at $9. It needs macOS 15.&lt;/p&gt;

&lt;p&gt;ActionClip is for anyone who copies text into another app just to do one small thing with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Trailback
&lt;/h2&gt;

&lt;p&gt;You saw a page, a file, or a screenshot last week, and now you can’t remember what it was called or where it was. &lt;a href="https://trailback.app" rel="noopener noreferrer"&gt;Trailback&lt;/a&gt; keeps a private record of the pages you read, the files you open, the screenshots you take, and the text you copy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frnx2u287livhymgugrg7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frnx2u287livhymgugrg7.png" alt="Trailback asking what you’re trying to remember, with a timeline of today" width="800" height="500"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Trailback’s search and timeline (image from Trailback)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Describe what you remember, like “the lease agreement I signed last month,” and it finds it. It reads the words inside PDFs, documents, and screenshots, so the file name doesn’t matter. You can also go back to a moment, like yesterday afternoon, and reopen everything you had open then.&lt;/p&gt;

&lt;p&gt;Its memory stays encrypted on your Mac. It skips private windows and passwords, and it only goes online to check your license and get updates.&lt;/p&gt;

&lt;p&gt;For Cyber Monday, it’s $9 once instead of $19. It needs macOS 13.&lt;/p&gt;

&lt;p&gt;If you’ve ever spent ten minutes looking for a page you know you read, Trailback is worth a look.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Tucket
&lt;/h2&gt;

&lt;p&gt;Spotlight in macOS 26 keeps what you copied for up to a week, but you can’t pin anything or keep it longer. &lt;a href="https://trytucket.com" rel="noopener noreferrer"&gt;Tucket&lt;/a&gt; keeps all of it. It pulls down from the notch and sorts everything you copy by type, like text, links, colors, images, SVGs, and icons.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc5kut0s1vu3wtdu5gepe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc5kut0s1vu3wtdu5gepe.png" alt="Tucket’s clipboard history, with clips sorted into links, colors, images, and text" width="800" height="500"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Tucket’s clipboard history, sorted by type (image from Tucket)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It reads the text inside every picture you copy, so you can find a screenshot by a word in it and copy that text out. Pinboards hold the clips you reuse, like a trip’s bookings or a brand’s colors, and they’re never cleared. You can also add a note to a clip or set a reminder to bring it back.&lt;/p&gt;

&lt;p&gt;It leaves out passwords, keys, and card numbers, and everything stays on your Mac.&lt;/p&gt;

&lt;p&gt;For Cyber Monday, the code BLACKFRIDAY40 takes 40% off, so it’s $6 instead of $10, paid once. It needs macOS 14.&lt;/p&gt;

&lt;p&gt;Tucket is for anyone who copies something, then copies something else, and loses the first one.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Woday
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.woday.app" rel="noopener noreferrer"&gt;Woday&lt;/a&gt; puts your calendar, tasks, reminders, and notes in a single Mac app and lets them link to each other. A meeting can have its tasks and notes attached, and you can join the call from Woday.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmn0s7i5khl6jnlseygrc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmn0s7i5khl6jnlseygrc.png" alt="Woday’s Today view with a week strip, tasks, and an inbox" width="800" height="420"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Woday’s Today view (image from Woday)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Tasks can have subtasks, priorities, and tags, and repeating ones can turn into habits. You can see them as a list, a Kanban board, or on the calendar. Notes use a block editor like Notion’s, and you can add tasks and events from inside a page.&lt;/p&gt;

&lt;p&gt;It syncs with Apple Calendar and pulls in tasks and events from Todoist, Linear, Obsidian, TickTick, Notion, and Google Calendar. Your data syncs through your own iCloud, and a keyboard shortcut lets you add a task or an event from any app.&lt;/p&gt;

&lt;p&gt;A lifetime license is $19 instead of $39, with a 14-day money-back guarantee. It needs macOS 26.&lt;/p&gt;

&lt;p&gt;Woday is for anyone who keeps a calendar in one app, tasks in another, and notes in a third.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. SpaceWise
&lt;/h2&gt;

&lt;p&gt;If you write code on a Mac, your disk fills up with things you never saved yourself. Old &lt;code&gt;node_modules&lt;/code&gt; folders, Docker images, Xcode’s DerivedData, unused simulators, and AI models you tried once all add up.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.spacewisemac.in" rel="noopener noreferrer"&gt;SpaceWise&lt;/a&gt; finds that space and tells you what’s safe to clear. Before it suggests deleting a project’s folders, it checks the lockfile and the project’s Git status.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F437g8xvuqwy7eaqkfwda.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F437g8xvuqwy7eaqkfwda.png" alt="SpaceWise’s storage overview, with space to reclaim in projects, toolchains, Docker, and Xcode" width="800" height="512"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;SpaceWise’s storage overview (image from SpaceWise)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Anything it removes goes to the Trash first, so you can undo it. Scans run on your Mac, with no tracking.&lt;/p&gt;

&lt;p&gt;The free version maps your storage and cleans up to 1.5 GB. Lifetime Pro is $7.99 for up to three devices, and the code BLACKFRI25 takes 25% off. It needs macOS 13.&lt;/p&gt;

&lt;p&gt;SpaceWise is for developers whose storage bar is always in the red.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Halo
&lt;/h2&gt;

&lt;p&gt;On a MacBook, the notch is dead space. &lt;a href="https://halo-mac.com" rel="noopener noreferrer"&gt;Halo&lt;/a&gt; turns it into a live strip, like the Dynamic Island on an iPhone. On a Mac without a notch, it uses the top edge of the screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fydohx96u64yvf1beua3z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fydohx96u64yvf1beua3z.png" alt="Halo in the MacBook notch, showing when Claude Code is working, needs you, and is done" width="800" height="500"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Halo in the notch, showing when Claude Code is working, needs you, and is done (image from Halo)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Messages from Slack, Mail, and Telegram show up there, along with music, calls, meetings, timers, downloads, and screenshots. Holding Fn lets you dictate into the app under your cursor. If you use Claude Code or Codex, it shows when they’re working, when they need you, and when they’re done.&lt;/p&gt;

&lt;p&gt;It runs without an account. For Cyber Monday, the code BLACKFRIDAY55 takes 55% off, so it’s about $4.50 instead of $9.99. It needs macOS 15.&lt;/p&gt;

&lt;p&gt;Halo is for anyone with a MacBook who wants the notch to do something.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to start
&lt;/h2&gt;

&lt;p&gt;Start with the problem you run into most. Get Vitals if your Mac slows down and you can’t tell why, SoundBar if you take calls while something else is playing, and Levers if your menu bar is crowded or you’re always in System Settings. Flit is the pick if you’d rather talk than type, ActionClip if you work with a lot of text, and Trailback if you keep losing things you’ve already seen. Tucket is for anyone who copies a lot, and Woday suits anyone juggling a calendar, tasks, and notes. SpaceWise is for developers short on space, and Halo is for MacBook owners who want more from the notch.&lt;/p&gt;

&lt;p&gt;For more, MacBase lists every Mac app deal running this Cyber Monday, with its code. You can &lt;a href="https://macbase.app/deals" rel="noopener noreferrer"&gt;see them all here&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I’m Atta. I make Mac apps at &lt;a href="https://fore.studio" rel="noopener noreferrer"&gt;Fore Studio&lt;/a&gt; that you pay for once, including Vitals, Levers, SoundBar, and Flit, and I write about getting more done on a Mac. Follow me on X at &lt;a href="https://x.com/attacomsian" rel="noopener noreferrer"&gt;@attacomsian&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>macos</category>
      <category>productivity</category>
      <category>devtools</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Why Is Your Mac So Slow? 5 Causes, Plus What Slows Down a Developer's Mac</title>
      <dc:creator>Atta 🐬</dc:creator>
      <pubDate>Thu, 26 Nov 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/attacomsian/why-is-your-mac-so-slow-5-causes-plus-what-slows-down-a-developers-mac-1b8m</link>
      <guid>https://dev.to/attacomsian/why-is-your-mac-so-slow-5-causes-plus-what-slows-down-a-developers-mac-1b8m</guid>
      <description>&lt;p&gt;If your Mac has started to lag, you know the signs. The cursor spins. Apps take a few seconds to switch. The fans come on while you're only reading email.&lt;/p&gt;

&lt;p&gt;I built &lt;a href="https://vitalsmac.com" rel="noopener noreferrer"&gt;a system monitor for the Mac&lt;/a&gt;, so I spend more time in Activity Monitor than most people. And when an Apple silicon Mac is slow, it's rarely because it's getting old. It's usually one of five things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An app stuck using too much CPU&lt;/li&gt;
&lt;li&gt;Memory running out&lt;/li&gt;
&lt;li&gt;Heat&lt;/li&gt;
&lt;li&gt;A nearly full disk&lt;/li&gt;
&lt;li&gt;macOS catching up on housekeeping after an update&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don't need to install anything to find out which one it is. Activity Monitor is already on your Mac, and it takes about five minutes once you know where to look. Let's go through it tab by tab.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open Activity Monitor
&lt;/h2&gt;

&lt;p&gt;Press Command-Space, type &lt;strong&gt;Activity Monitor&lt;/strong&gt;, and press Return. You'll also find it in &lt;strong&gt;Applications › Utilities&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Along the top are five tabs: &lt;strong&gt;CPU&lt;/strong&gt;, &lt;strong&gt;Memory&lt;/strong&gt;, &lt;strong&gt;Energy&lt;/strong&gt;, &lt;strong&gt;Disk&lt;/strong&gt;, and &lt;strong&gt;Network&lt;/strong&gt;. For a slow Mac, the first two matter most.&lt;/p&gt;

&lt;p&gt;Before you start, change two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose &lt;strong&gt;View › All Processes&lt;/strong&gt;, so nothing is hidden.&lt;/li&gt;
&lt;li&gt;Click a column's name to sort by it. Click it again to put the biggest numbers at the top.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Check the CPU tab
&lt;/h2&gt;

&lt;p&gt;Click &lt;strong&gt;CPU&lt;/strong&gt; and sort by &lt;strong&gt;% CPU&lt;/strong&gt;, highest first. The top few rows are what's working hardest right now. Apple's guide to &lt;a href="https://support.apple.com/guide/activity-monitor/actmntr43452/mac" rel="noopener noreferrer"&gt;viewing CPU activity&lt;/a&gt; explains every column.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7q6pp68t0db0slb5fggf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7q6pp68t0db0slb5fggf.png" alt="Activity Monitor's CPU tab sorted by % CPU, with Claude Helper, WindowServer, FluidVoice, and kernel_task at the top, and Idle at 76% in the panel below" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's what to look for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One app far above the rest&lt;/strong&gt;, at 100% or more, for minutes at a time. 100% means one full CPU core, so a busy app can go well past it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Idle at the bottom of the window.&lt;/strong&gt; When your Mac isn't doing much, it should be high, often above 90%. If it stays low while you're only reading or writing, something is busy in the background.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An app you aren't using&lt;/strong&gt; near the top. It's often a stuck browser tab, a sync that never finishes, or an app that's misbehaving.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Short bursts are fine. Opening an app, exporting a video, or building code should use a lot of CPU and then settle down. What slows your Mac is something that stays high.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Check memory pressure
&lt;/h2&gt;

&lt;p&gt;Click &lt;strong&gt;Memory&lt;/strong&gt;. Don't worry about the big &lt;strong&gt;Memory Used&lt;/strong&gt; number. macOS fills free memory with cached files on purpose, so a Mac with little "free" memory isn't necessarily short of it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3aadcmg5rv33l4ogw08g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3aadcmg5rv33l4ogw08g.png" alt="Activity Monitor's Memory tab sorted by Memory, with Google Chrome and its helpers spread across many rows, and a green Memory Pressure graph with 11.37 GB of Swap Used in the panel below" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The number that matters is the &lt;strong&gt;Memory Pressure&lt;/strong&gt; graph at the bottom:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Green:&lt;/strong&gt; memory is being used well. Memory isn't your problem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Yellow:&lt;/strong&gt; macOS is compressing memory to make room. Quit apps you aren't using, especially browsers with lots of tabs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Red:&lt;/strong&gt; your apps need more memory than your Mac has. Quit apps now. If it's often red, your Mac needs more memory for the way you use it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next to the graph, &lt;strong&gt;Swap Used&lt;/strong&gt; shows how much memory macOS has moved to the disk. A little is fine. If it's several gigabytes and still growing while you work, your Mac is short of memory, and that's when everything slows down. Apple's page on &lt;a href="https://support.apple.com/guide/activity-monitor/actmntr1004/mac" rel="noopener noreferrer"&gt;memory usage in Activity Monitor&lt;/a&gt; covers the rest of the panel.&lt;/p&gt;

&lt;p&gt;Sort by &lt;strong&gt;Memory&lt;/strong&gt; to see which apps are using the most. It's usually a browser, a design app, Xcode, a virtual machine, or a local AI model. In my screenshot above, it's Chrome, spread across so many rows that it's hard to tell how much it uses in total.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Check the Energy tab
&lt;/h2&gt;

&lt;p&gt;If battery life bothers you more than speed, click &lt;strong&gt;Energy&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgftapk13ze89rflj2x7i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgftapk13ze89rflj2x7i.png" alt="Activity Monitor's Energy tab showing Applications in Last 12 Hours, sorted by Energy Impact, with the 12 hr Power and Preventing Sleep columns and the battery graph for the last 12 hours below" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Energy Impact&lt;/strong&gt; shows how much power each app is using right now. Sort by it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;12 hr Power&lt;/strong&gt; shows the same thing over the last 12 hours, so you can catch the app that drained your battery while you weren't looking. You'll see it when &lt;strong&gt;View&lt;/strong&gt; is set to &lt;strong&gt;Applications in Last 12 Hours&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Preventing Sleep&lt;/strong&gt; shows which apps are keeping your Mac awake.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 4: Check your storage
&lt;/h2&gt;

&lt;p&gt;A nearly full disk slows everything down because macOS needs free space for swap, caches, and updates. Open &lt;strong&gt;System Settings › General › Storage&lt;/strong&gt; to see how much you have left.&lt;/p&gt;

&lt;p&gt;Try to keep at least 10% of the disk free, or more if you edit video or run virtual machines. If you're short, start with the recommendations on that Storage page. Apple's guide to &lt;a href="https://support.apple.com/en-us/102624" rel="noopener noreferrer"&gt;freeing up storage space&lt;/a&gt; goes through each one. Apps like &lt;a href="https://diskmate.app" rel="noopener noreferrer"&gt;DiskMate&lt;/a&gt; show you what's filling the disk. If you build software, &lt;a href="https://spacewisemac.in" rel="noopener noreferrer"&gt;SpaceWise&lt;/a&gt; finds the caches developer tools leave behind, and those can run to tens of gigabytes.&lt;/p&gt;

&lt;p&gt;While you're in Activity Monitor, the &lt;strong&gt;Disk&lt;/strong&gt; tab shows which apps are reading and writing the most right now. It helps when your Mac stutters during a backup or a sync.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to quit an app safely
&lt;/h2&gt;

&lt;p&gt;Select the app in Activity Monitor and click the &lt;strong&gt;Stop&lt;/strong&gt; button (the X in a circle) at the top of the window. Then choose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Quit&lt;/strong&gt; asks the app to close and lets it save your work. Try this first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Force Quit&lt;/strong&gt; closes it right away. Anything you haven't saved in that app is lost.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If an app has stopped responding, Option-Command-Escape opens the Force Quit window without Activity Monitor.&lt;/p&gt;

&lt;p&gt;One warning: don't quit processes you don't recognize just because they're near the top. Some of them are macOS itself, and quitting them logs you out or restarts your Mac. Here are the ones people ask about most.&lt;/p&gt;

&lt;h2&gt;
  
  
  The processes that look scary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;kernel_task&lt;/strong&gt; is macOS itself. When your Mac gets hot, it takes CPU time away from other apps so the Mac can cool down. Don't quit it. Find what's making your Mac hot, and keep the vents clear.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WindowServer&lt;/strong&gt; draws everything on your screens. It's normal under load, and it goes up with more displays, more windows, and lots of animation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;mds, mds_stores, and mdworker&lt;/strong&gt; are Spotlight indexing your files. They're busy for a while after an update, a migration, or copying lots of files. Give them time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;photoanalysisd and mediaanalysisd&lt;/strong&gt; are Photos recognizing faces, objects, and text after you import photos. They do most of their work when your Mac is idle and plugged in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;backupd&lt;/strong&gt; is Time Machine backing up. Let the backup finish.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;bird, cloudd, and fileproviderd&lt;/strong&gt; are iCloud Drive syncing. If they never settle, check iCloud Drive in Finder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Google Chrome Helper (Renderer)&lt;/strong&gt; is one Chrome tab or extension each. Close tabs you don't need, or find the heavy one in Chrome's Task Manager.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;launchd and loginwindow&lt;/strong&gt; start and run everything else. Never quit these.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Other fixes worth trying
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Restart.&lt;/strong&gt; It clears memory, ends stuck processes, and finishes installing updates. If your Mac hasn't restarted in weeks, start here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check your login items.&lt;/strong&gt; In &lt;strong&gt;System Settings › General › Login Items &amp;amp; Extensions&lt;/strong&gt;, turn off the apps you don't need running all the time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Update macOS and your apps.&lt;/strong&gt; A lot of slowdowns are bugs that have already been fixed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Give it a day after a big update.&lt;/strong&gt; Spotlight and Photos re-index in the background, and your Mac can feel slow until they're done.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watch the heat.&lt;/strong&gt; A MacBook Air has no fan, so it slows itself down to stay cool under a long load. Using it on a bed or your lap traps the heat.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  If you're a developer
&lt;/h2&gt;

&lt;p&gt;A developer's Mac has a few more ways to slow down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Xcode builds.&lt;/strong&gt; A build uses every core it can get, so the Mac feels slow until it finishes. Old builds also pile up in &lt;code&gt;~/Library/Developer/Xcode/DerivedData&lt;/code&gt;, often tens of gigabytes. It's safe to delete, because Xcode rebuilds what it needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simulators.&lt;/strong&gt; A simulator you've booted keeps running after you quit the Simulator app. &lt;code&gt;xcrun simctl shutdown all&lt;/code&gt; shuts them all down.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docker.&lt;/strong&gt; Docker Desktop runs your containers inside one Linux virtual machine, so Activity Monitor shows a single process using a lot of memory and can't tell you which container it is. &lt;code&gt;docker stats&lt;/code&gt; shows each container's CPU and memory, and the Resources page in Docker Desktop's settings caps how much memory the virtual machine can take.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dev servers you forgot about.&lt;/strong&gt; A &lt;code&gt;node&lt;/code&gt; or &lt;code&gt;python&lt;/code&gt; process from last week can still be holding a port and memory. &lt;code&gt;lsof -i :3000&lt;/code&gt; shows what's on port 3000.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Coding agents.&lt;/strong&gt; Claude Code, Codex, and other agents start shells, builds, and dev servers of their own. In Activity Monitor, that's dozens of rows with no project name on any of them.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Where Activity Monitor falls short
&lt;/h2&gt;

&lt;p&gt;Activity Monitor is good at the basics. But when you're trying to find out why your Mac is slow, it gets in your way in four places:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It lists processes, not apps.&lt;/strong&gt; Chrome, Slack, VS Code, and most modern apps run as dozens of helper processes, each on its own row. The app eating your CPU is spread across the list, and you have to add it up yourself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It barely remembers anything.&lt;/strong&gt; Apart from 12 hours of energy use, it only shows what's happening right now. If your Mac was slow an hour ago and it's fine now, there's nothing to look at.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It doesn't show temperatures or fans.&lt;/strong&gt; macOS doesn't tell you how hot your Mac is anywhere.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It isn't in the menu bar.&lt;/strong&gt; You only see a problem once you open it and go looking.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Vitals: see which app is slowing your Mac
&lt;/h2&gt;

&lt;p&gt;Those four problems are why I built &lt;a href="https://vitalsmac.com" rel="noopener noreferrer"&gt;Vitals&lt;/a&gt;. It answers the question this whole guide is about: which app is slowing my Mac, and since when?&lt;/p&gt;

&lt;h3&gt;
  
  
  Apps instead of processes
&lt;/h3&gt;

&lt;p&gt;Vitals counts every helper process under the app it belongs to. So instead of about 1,000 processes, you see about 40 to 60 apps. Below, Google Chrome is a single row: 23.88 GB across 123 processes. I've opened it up to show its tabs, the browser, the GPU process, and its extensions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fw27slv3ileuzc2grnatq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fw27slv3ileuzc2grnatq.png" alt="Vitals' Memory tab, with Google Chrome as one row of 23.88 GB and 123 processes, opened into Tabs, Browser, GPU, Extensions, Other Processes, and Network" width="800" height="573"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What slowed it down earlier
&lt;/h3&gt;

&lt;p&gt;Vitals keeps up to a year of history, hour by hour, for your Mac and for every app. So you can answer "what was slowing my Mac at 3 pm?" or "has this app been growing in memory all week?"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5j2iin041xg8n16whze4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5j2iin041xg8n16whze4.png" alt="Vitals' Over Time view for the last 24 hours, with average CPU load and the top apps by CPU time" width="799" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  A warning before it gets slow
&lt;/h3&gt;

&lt;p&gt;CPU, memory, temperatures, fans, and more can each sit in your menu bar and turn red when your Mac is under strain. Vitals also sends you a notification when an app uses too much CPU, keeps growing in memory, or hammers the disk.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frbqaur1ozewv0bxor8fh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frbqaur1ozewv0bxor8fh.png" alt="Vitals in the menu bar showing CPU, memory, network, and temperature, with its Overview open below" width="800" height="628"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Heat and fans
&lt;/h3&gt;

&lt;p&gt;Vitals reads every temperature sensor. On Macs with fans, it can set them to a fixed speed, follow a curve, or run at full speed for a while, so a hot Mac cools down before it slows down.&lt;/p&gt;

&lt;h3&gt;
  
  
  For developers
&lt;/h3&gt;

&lt;p&gt;Vitals also has a Developer tab and an Agents tab for the problems above:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every process grouped under its project, every port in use with what's holding it, and dev servers that have been left running.&lt;/li&gt;
&lt;li&gt;Docker containers, each with its own memory, CPU, network, and ports, and a Stop button.&lt;/li&gt;
&lt;li&gt;Coding agents like Claude Code, Codex, and Gemini CLI, each session with its project, what it's doing, and what it started, plus how much is left of each AI plan and when it resets.&lt;/li&gt;
&lt;li&gt;A Process Inspector: click any process for its code signature, parent process, full command line, and the CPU time, memory, open files, and listening ports it has used since it started.&lt;/li&gt;
&lt;li&gt;An MCP server, so Claude, Codex, Cursor, or any assistant that speaks MCP can ask what's running or what's on a port. Quitting anything still goes through you.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;vitals&lt;/code&gt; command that answers from the running app, as a table or as JSON:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew install --cask foredotstudio/tap/vitals
vitals whats-wrong
vitals ports
vitals agents --json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Price
&lt;/h3&gt;

&lt;p&gt;$12.99 for a lifetime license for Black Friday (usually $49), or $12 with a year of updates (it keeps working after that), with a 3-day free trial of everything. Vitals is sold on its own site and needs macOS 15 Sequoia or later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Why is my Mac so slow all of a sudden?
&lt;/h3&gt;

&lt;p&gt;Usually one app is using too much CPU or memory, the disk is nearly full, or macOS is indexing after an update. Open Activity Monitor, sort the CPU tab by % CPU, and check the Memory Pressure graph in the Memory tab. If nothing stands out, restart your Mac.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is it safe to quit kernel_task?
&lt;/h3&gt;

&lt;p&gt;No, and you can't. kernel_task is macOS itself. When it uses a lot of CPU, it's keeping other apps off the CPU so your Mac can cool down. Find what's making your Mac hot instead.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why is WindowServer using so much CPU?
&lt;/h3&gt;

&lt;p&gt;WindowServer draws everything on your screens. It works harder with more displays, higher resolutions, more open windows, and more animation. Closing windows you don't need and unplugging a display you aren't using will bring it down.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is memory pressure on a Mac?
&lt;/h3&gt;

&lt;p&gt;It's how hard macOS is working to fit your apps into memory, shown as a graph in Activity Monitor's Memory tab. Green is fine. Yellow means macOS is compressing memory. Red means your apps need more memory than your Mac has, and it will slow down.&lt;/p&gt;

&lt;h3&gt;
  
  
  How much free storage does a Mac need?
&lt;/h3&gt;

&lt;p&gt;Keep at least 10% of the disk free, so macOS has room for swap, caches, and updates. You can check it in System Settings › General › Storage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does Activity Monitor slow down my Mac?
&lt;/h3&gt;

&lt;p&gt;Barely. It uses a little CPU while its window is open, and nothing once you quit it.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I'm Atta. I make Mac apps at &lt;a href="https://fore.studio" rel="noopener noreferrer"&gt;Fore Studio&lt;/a&gt; that you pay for once, including Vitals, Levers, SoundBar, and Flit, and I write about getting more done on a Mac. Follow me on X at &lt;a href="https://x.com/attacomsian" rel="noopener noreferrer"&gt;@attacomsian&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>macos</category>
      <category>productivity</category>
      <category>devtools</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Does Mac Have a Volume Mixer? How to Set a Different Volume for Each App</title>
      <dc:creator>Atta 🐬</dc:creator>
      <pubDate>Wed, 25 Nov 2026 10:18:00 +0000</pubDate>
      <link>https://dev.to/attacomsian/does-mac-have-a-volume-mixer-how-to-set-a-different-volume-for-each-app-56bb</link>
      <guid>https://dev.to/attacomsian/does-mac-have-a-volume-mixer-how-to-set-a-different-volume-for-each-app-56bb</guid>
      <description>&lt;p&gt;&lt;strong&gt;Black Friday is live at &lt;a href="https://fore.studio/?utm_source=devto" rel="noopener noreferrer"&gt;Fore Studio&lt;/a&gt;: SoundBar and my other Mac apps are up to 76% off until December 5.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You're on a Zoom call with a client. Spotify is playing in the background, Slack pings every few seconds, and a video in another tab starts on its own. You want the call loud, the music quiet and Slack silent. On a Mac, that's harder than it should be: the volume keys turn everything up or down together.&lt;/p&gt;

&lt;p&gt;Windows has had a volume mixer for years. macOS still doesn't. Here's what you can do with what's built in, where that stops, and how to give each app a volume of its own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Does macOS have a volume mixer?
&lt;/h2&gt;

&lt;p&gt;No. macOS has one volume for each output, such as your speakers or AirPods, and every app plays at that level. The volume keys, the slider in Control Center and the one in &lt;strong&gt;System Settings &amp;gt; Sound&lt;/strong&gt; all change that same volume. That's still true in macOS 27 Golden Gate.&lt;/p&gt;

&lt;p&gt;The reason is how macOS handles sound. Every app sends its audio to Core Audio, which mixes it all together before it reaches your speakers. The volume is set on the speakers, after the mix, so there's no single place to turn one app down.&lt;/p&gt;

&lt;p&gt;Apps can work around that. Since macOS 14.2 Sonoma, Core Audio lets an app take in another app's sound, once you allow it, and play it back at a different level. That's how a per-app volume mixer works on a recent Mac, without the extra audio device older mixers had to install.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you can do without an app
&lt;/h2&gt;

&lt;p&gt;None of these give you a mixer, but together they cover a lot of what people want one for.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use each app's own volume
&lt;/h3&gt;

&lt;p&gt;Many apps have a volume of their own, separate from the Mac's. Music and Spotify have a slider in their window, video players have one in their controls, and Zoom has a speaker volume in &lt;strong&gt;Settings &amp;gt; Audio&lt;/strong&gt;. Turn the Mac's volume up, then turn down the app you want quieter.&lt;/p&gt;

&lt;p&gt;It works, but every app keeps its slider somewhere different, and many apps, like Slack or Messages, don't have one at all.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mute a browser tab
&lt;/h3&gt;

&lt;p&gt;A tab playing sound shows a speaker icon.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Safari:&lt;/strong&gt; click the speaker icon in the tab, or in the Smart Search field, to mute it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chrome:&lt;/strong&gt; right-click the tab and choose &lt;strong&gt;Mute site&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Firefox:&lt;/strong&gt; click the speaker icon on the tab, or right-click it and choose &lt;strong&gt;Mute Tab&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can mute a tab, but not set it to half volume.&lt;/p&gt;

&lt;h3&gt;
  
  
  Turn down alert sounds
&lt;/h3&gt;

&lt;p&gt;Alerts and sound effects have a volume of their own. Open &lt;strong&gt;System Settings &amp;gt; Sound&lt;/strong&gt; and drag the &lt;strong&gt;Alert volume&lt;/strong&gt; slider. You can also choose where they play, under &lt;strong&gt;Play sound effects through&lt;/strong&gt;, so alerts come out of the Mac's speakers while music plays in your headphones.&lt;/p&gt;

&lt;h3&gt;
  
  
  Turn off one app's notification sounds
&lt;/h3&gt;

&lt;p&gt;If one app keeps pinging, open &lt;strong&gt;System Settings &amp;gt; Notifications&lt;/strong&gt;, choose the app and turn off &lt;strong&gt;Play sound for notifications&lt;/strong&gt;. Its notifications still show, without the sound.&lt;/p&gt;

&lt;h3&gt;
  
  
  Change the volume in smaller steps
&lt;/h3&gt;

&lt;p&gt;Hold &lt;strong&gt;Option&lt;/strong&gt; and &lt;strong&gt;Shift&lt;/strong&gt; while you press the volume keys to change the volume in quarter steps. It doesn't help with one app, but it makes it easier to find a level that suits everything at once.&lt;/p&gt;

&lt;h3&gt;
  
  
  Play through two outputs at once
&lt;/h3&gt;

&lt;p&gt;In &lt;strong&gt;Audio MIDI Setup&lt;/strong&gt;, in Applications &amp;gt; Utilities, you can click &lt;strong&gt;+&lt;/strong&gt; and create a &lt;strong&gt;Multi-Output Device&lt;/strong&gt; that plays through several outputs at the same time, such as two pairs of headphones. It sends every app to every output, though, and the volume keys can't change a multi-output device's volume. It's for sharing sound, not for splitting it by app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where this stops
&lt;/h3&gt;

&lt;p&gt;With what's built in, you can't:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set one app to 30% and another to 80%.&lt;/li&gt;
&lt;li&gt;Turn down an app that has no volume control of its own, like Slack or a game.&lt;/li&gt;
&lt;li&gt;Send one app to your speakers and another to your AirPods.&lt;/li&gt;
&lt;li&gt;Make a quiet app louder than the Mac's maximum.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For those, you need a volume mixer.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to set a volume for each app with SoundBar
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://soundbarmac.com" rel="noopener noreferrer"&gt;SoundBar&lt;/a&gt; is a per-app volume mixer for Mac. It gives every app that plays sound its own volume slider, from 0% to 200%, with a mute button, an equalizer and its own output device. It opens from the notch on a MacBook, or from the menu bar on a Mac without one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6are02ycojmo6vnk2jqq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6are02ycojmo6vnk2jqq.png" alt="SoundBar's mixer, with volume sliders for Music, Safari, Zoom, Brave and Slack, an equalizer for Music, and the output and microphone in use" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Download SoundBar&lt;/strong&gt; from &lt;a href="https://soundbarmac.com" rel="noopener noreferrer"&gt;soundbarmac.com&lt;/a&gt; and open it. Every feature is free for 3 days, with no account and no card.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Allow audio access&lt;/strong&gt; when macOS asks. SoundBar has to pass each app's sound through itself to change its volume, so macOS asks once. Nothing is recorded or sent anywhere.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Play something.&lt;/strong&gt; Open SoundBar from the notch, or from its icon in the menu bar. Every app that's playing sound is listed. Click &lt;strong&gt;All&lt;/strong&gt; to see every app.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Drag an app's slider&lt;/strong&gt; to set its volume, or click its mute button. Each app keeps its volume between launches.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Send an app to a different output
&lt;/h3&gt;

&lt;p&gt;Click the &lt;strong&gt;⋯&lt;/strong&gt; button on an app's row, choose &lt;strong&gt;Play Through&lt;/strong&gt; and pick a device. Music can play through the speakers while a call goes to your AirPods.&lt;/p&gt;

&lt;h3&gt;
  
  
  Make a quiet app louder
&lt;/h3&gt;

&lt;p&gt;Drag an app's slider past 100%, up to 200%. It's useful for a quiet video or a call with someone far from their microphone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let the volume keys change one app
&lt;/h3&gt;

&lt;p&gt;In SoundBar's settings, open &lt;strong&gt;Notch&lt;/strong&gt; and turn on &lt;strong&gt;Take over the keyboard's volume keys&lt;/strong&gt;. Then hold &lt;strong&gt;Option&lt;/strong&gt; while you press the volume keys to change the app in front instead of the whole Mac. macOS asks for Accessibility access the first time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Turn everything else down during calls
&lt;/h3&gt;

&lt;p&gt;When an app starts using the microphone, SoundBar fades the other apps down, to 30% by default, and brings them back when the call ends.&lt;/p&gt;

&lt;p&gt;SoundBar needs macOS 15 Sequoia or later, on Apple silicon or Intel. It's $29, paid once, or $6.99 until December 5 for Black Friday.&lt;/p&gt;

&lt;p&gt;Using SoundSource? SoundBar can replace it. Compare SoundBar with other &lt;a href="https://macbase.app/alternatives/soundsource" rel="noopener noreferrer"&gt;SoundSource alternatives&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  If something isn't working
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;An app isn't in the list.&lt;/strong&gt; SoundBar shows apps when they play sound. Start playing something in the app, or click &lt;strong&gt;All&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An app is still too quiet.&lt;/strong&gt; Turn up the Mac's volume first, then raise the app past 100%.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The volume keys change everything.&lt;/strong&gt; That's macOS's default. Turn on &lt;strong&gt;Take over the keyboard's volume keys&lt;/strong&gt; in SoundBar's settings, then hold &lt;strong&gt;Option&lt;/strong&gt; with the volume keys.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sound plays through the wrong device.&lt;/strong&gt; Check the app's &lt;strong&gt;Play Through&lt;/strong&gt; device in SoundBar, then the Mac's output in &lt;strong&gt;System Settings &amp;gt; Sound&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How do I mute one app on a Mac?
&lt;/h3&gt;

&lt;p&gt;If the app has its own volume or mute, use that. For a browser tab, click the speaker icon in Safari or right-click the tab and choose Mute site in Chrome. For notification sounds, turn off Play sound for notifications for that app in System Settings &amp;gt; Notifications. To mute any app, use a per-app volume mixer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can different apps play through different speakers on a Mac?
&lt;/h3&gt;

&lt;p&gt;Not with what's built in. Some apps, like Zoom, let you pick their speaker in their own settings, but most play through the Mac's output. A mixer like SoundBar lets you choose an output device for each app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I make an app louder than 100% on a Mac?
&lt;/h3&gt;

&lt;p&gt;Not with macOS's own volume. SoundBar can raise an app up to 200% of its normal level.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why can't I change the volume of a multi-output device?
&lt;/h3&gt;

&lt;p&gt;A multi-output device made in Audio MIDI Setup has no volume of its own, so the volume keys don't change it. To change it, select each output in Audio MIDI Setup and set its volume there, or use each app's own volume.&lt;/p&gt;

&lt;p&gt;For more small apps that fix what macOS leaves out, read &lt;a href="https://macbase.app/blog/best-menu-bar-apps-mac" rel="noopener noreferrer"&gt;14 Best Menu Bar Apps for Mac&lt;/a&gt;, or browse &lt;a href="https://macbase.app/categories/music-audio" rel="noopener noreferrer"&gt;Music &amp;amp; Audio apps&lt;/a&gt; on MacBase.&lt;/p&gt;

</description>
      <category>macos</category>
      <category>productivity</category>
      <category>tutorial</category>
      <category>apple</category>
    </item>
    <item>
      <title>23 Best Places to Promote Your Mac App in 2026</title>
      <dc:creator>Atta 🐬</dc:creator>
      <pubDate>Mon, 23 Nov 2026 16:43:38 +0000</pubDate>
      <link>https://dev.to/attacomsian/23-best-places-to-promote-your-mac-app-in-2026-3lan</link>
      <guid>https://dev.to/attacomsian/23-best-places-to-promote-your-mac-app-in-2026-3lan</guid>
      <description>&lt;p&gt;You've finished your Mac app. Now you need people to find it, and the Mac App Store won't do that for you. Most of the apps listed on &lt;a href="https://macbase.app" rel="noopener noreferrer"&gt;MacBase&lt;/a&gt; aren't even in it.&lt;/p&gt;

&lt;p&gt;Most launch advice doesn't help much either. It's written for web startups, so it hands you a long list of directories where nobody is looking for a Mac app.&lt;/p&gt;

&lt;p&gt;This list is only about launching a Mac app. It ranks 23 places by what worked for me and by whether the people there want a Mac app, with what each one costs and the rules you need to know. I've launched four Mac apps since September: &lt;a href="https://flit.fyi" rel="noopener noreferrer"&gt;Flit&lt;/a&gt;, &lt;a href="https://vitalsmac.com" rel="noopener noreferrer"&gt;Vitals&lt;/a&gt;, &lt;a href="https://leversmac.com" rel="noopener noreferrer"&gt;Levers&lt;/a&gt; and &lt;a href="https://soundbarmac.com" rel="noopener noreferrer"&gt;SoundBar&lt;/a&gt;. &lt;strong&gt;All four are up to 76% off for Black Friday at &lt;a href="https://fore.studio/?utm_source=devto&amp;amp;utm_campaign=promote-mac-app" rel="noopener noreferrer"&gt;Fore Studio&lt;/a&gt; until December 5, if you'd like to try them.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Vitals shows why the order isn't what you might expect. It sold its first 1,000 licenses in eight days, and almost all of them came from X, where it went viral. It also launched on Hacker News and on Product Hunt, where it was the fourth product of the day, which helped. But X is where the sales came from. That's one launch, and going viral isn't something you can plan, so here's the whole list.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Place&lt;/th&gt;
&lt;th&gt;Mac only&lt;/th&gt;
&lt;th&gt;Domain Rating&lt;/th&gt;
&lt;th&gt;Cost&lt;/th&gt;
&lt;th&gt;Watch out for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1. X&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;97&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Results vary a lot&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2. Product Hunt&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;92&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;You can't ask for upvotes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3. StartupBase&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;76&lt;/td&gt;
&lt;td&gt;Free, or from $39&lt;/td&gt;
&lt;td&gt;Mine; 4–5 week wait when free&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4. r/macapps&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;95 (reddit.com)&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Strict rules on who can post&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5. Hacker News&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;91&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;People must be able to try it without signing up&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6. Mac App Store&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;97 (apple.com)&lt;/td&gt;
&lt;td&gt;$99 a year, plus Apple's cut&lt;/td&gt;
&lt;td&gt;Your app must be sandboxed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7. Homebrew&lt;/td&gt;
&lt;td&gt;Mostly&lt;/td&gt;
&lt;td&gt;90&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Popularity rules for the main list&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8. MacBase&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;58&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;New, and it's mine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9. Mac press, in any language&lt;/td&gt;
&lt;td&gt;Mostly&lt;/td&gt;
&lt;td&gt;78 (MacStories)&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Nothing is guaranteed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10. AlternativeTo&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;82&lt;/td&gt;
&lt;td&gt;No fee mentioned&lt;/td&gt;
&lt;td&gt;Reviewed before it goes live&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11. Mac Menu Bar&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;Not stated&lt;/td&gt;
&lt;td&gt;Menu bar apps only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12. MacUpdate&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;77&lt;/td&gt;
&lt;td&gt;Check its form&lt;/td&gt;
&lt;td&gt;Review can take a while&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13. Setapp&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;80&lt;/td&gt;
&lt;td&gt;Revenue share&lt;/td&gt;
&lt;td&gt;For mature apps only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;14. Awesome lists on GitHub&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;97 (github.com)&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Curated by their maintainers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;15. Macfolio&lt;/td&gt;
&lt;td&gt;Mostly&lt;/td&gt;
&lt;td&gt;27&lt;/td&gt;
&lt;td&gt;Check its form&lt;/td&gt;
&lt;td&gt;Curated, and small&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16. Mac App Index&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;38&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Small and new&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;17. dotstore&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Over 100,000 apps, by its own count&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;18. Mac App Supply&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;26&lt;/td&gt;
&lt;td&gt;No fee mentioned&lt;/td&gt;
&lt;td&gt;Design matters; native apps only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;19. TryMacApps&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;66&lt;/td&gt;
&lt;td&gt;Free with its badge, or $39&lt;/td&gt;
&lt;td&gt;Badge must be on your site first&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20. MacNative&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;53&lt;/td&gt;
&lt;td&gt;Free, or a paid Pro option&lt;/td&gt;
&lt;td&gt;No browser wrappers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;21. Mac Menubar Apps&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;Check its form&lt;/td&gt;
&lt;td&gt;Menu bar apps only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;22. MacAIApps&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;AI apps only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;23. PayOnceApps&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;19&lt;/td&gt;
&lt;td&gt;Check its form&lt;/td&gt;
&lt;td&gt;One-time prices only&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Domain Rating is Ahrefs' score for a site's links, from 0 to 100, as of November 18, 2026. It tells you how strong a site is, not how much a link from it will help you, and it says nothing about whether its readers will buy your app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before you launch anywhere
&lt;/h2&gt;

&lt;p&gt;Every place below sends people to the same page, so do these first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Notarize the app.&lt;/strong&gt; People downloading from your site expect it, and Homebrew's cask rules require apps to pass Gatekeeper's checks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Offer a trial or a free version.&lt;/strong&gt; Show HN asks for no sign-up barrier, and an app people can open today does better everywhere.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write one plain sentence&lt;/strong&gt; that says what the app does. You'll paste it into every form on this list.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make a short video or a few real screenshots.&lt;/strong&gt; People decide on a Mac app by looking at it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set a low launch price.&lt;/strong&gt; More on that below.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. X
&lt;/h2&gt;

&lt;p&gt;Almost all of Vitals' first 1,000 licenses were sold here, so it comes first even though it isn't a Mac site. You can't count on going viral, but a post costs nothing, and you don't need anyone's approval.&lt;/p&gt;

&lt;p&gt;The launch isn't the end of it. If I were doing it again, I'd do what I've kept doing since: share every update as it ships. Each one gives people another reason to look.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Product Hunt
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.producthunt.com/launch" rel="noopener noreferrer"&gt;Product Hunt&lt;/a&gt; is free. It suggests launching at 12:01 am Pacific, and you can't directly ask people to upvote, only to visit and comment.&lt;/p&gt;

&lt;p&gt;Vitals was the fourth product of the day, and I think it helped. Its audience is mostly founders and people curious about new products rather than people looking for a Mac app, so it works best if you bring some momentum of your own. I wrote more about that in &lt;a href="https://attacomsian.com/blog/is-product-hunt-still-worth-it" rel="noopener noreferrer"&gt;Is Product Hunt still worth it?&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. StartupBase
&lt;/h2&gt;

&lt;p&gt;This one is mine. &lt;a href="https://startupbase.io/launch" rel="noopener noreferrer"&gt;StartupBase&lt;/a&gt; has published product launches since 2017, and it's the same kind of launch site as Product Hunt, so it's the natural next stop. It has a Domain Rating of 76, and your listing stays up after launch day.&lt;/p&gt;

&lt;p&gt;A free launch keeps a permanent listing, needs its badge on your site, and waits about 4–5 weeks. Premium starts at $39 and lets you pick a date, with a homepage feature and a permanent dofollow link.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. r/macapps
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.reddit.com/r/macapps/" rel="noopener noreferrer"&gt;r/macapps&lt;/a&gt; has about 260,000 members who are there to find and talk about Mac apps. No other place on this list fits as closely.&lt;/p&gt;

&lt;p&gt;It's also the strictest. Developers who don't qualify for the main feed have to post in the monthly megathread, The App Pile. You can self-promote at most once in 30 days, counted from your last app post, even if it was removed. You need 10 karma in the subreddit before promoting your app in comments, and you have to say the app is yours.&lt;/p&gt;

&lt;p&gt;The rules change, so read the sidebar before you post. Spend a few weeks commenting first, since you'll need the karma anyway.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Hacker News
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://news.ycombinator.com/showhn.html" rel="noopener noreferrer"&gt;Show HN&lt;/a&gt; is for things people can run on their own computers, which suits a Mac app. I posted Vitals here too. You have to have built the app yourself and be around to answer questions. It should be easy to try, without sign-ups or email gates, and you can't ask friends to upvote or comment.&lt;/p&gt;

&lt;p&gt;Apps with a clear technical angle tend to suit it, such as running on-device, working offline, or being open source. Keep the title plain, and stay in the thread all day.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Mac App Store
&lt;/h2&gt;

&lt;p&gt;The Mac App Store is where many people look first, and buying is one click with their Apple account. It's also the one place on this list that can feature you to everyone opening the store. None of my four apps is on it, so this is from Apple's rules rather than my own results.&lt;/p&gt;

&lt;p&gt;It costs $99 a year for the Apple Developer Program. Apple takes 15% through its &lt;a href="https://developer.apple.com/app-store/small-business-program/" rel="noopener noreferrer"&gt;Small Business Program&lt;/a&gt; if you earn under $1 million a year in proceeds, and its standard 30% above that. Your app must also be sandboxed, which rules out some utilities that need deeper access to the Mac.&lt;/p&gt;

&lt;h3&gt;
  
  
  Nominate your app for featuring
&lt;/h3&gt;

&lt;p&gt;If you're on the store, use &lt;a href="https://developer.apple.com/help/app-store-connect/manage-featuring-nominations/nominate-your-app-for-featuring/" rel="noopener noreferrer"&gt;Featuring Nominations&lt;/a&gt; in App Store Connect. It's Apple's own form for telling its editors about a launch, new content, or a big update, and it's the step most people skip.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.apple.com/app-store/getting-featured/" rel="noopener noreferrer"&gt;Apple asks&lt;/a&gt; for at least two weeks' notice and suggests up to three months for wider consideration, so do it before launch day. Apple has no checklist of requirements and doesn't promise anything, but the form takes little effort for what it could bring.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Homebrew
&lt;/h2&gt;

&lt;p&gt;Homebrew isn't a launch site, but many developers install Mac apps with it, and one install command is easy to share. There are two ways in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The main list.&lt;/strong&gt; To get into &lt;code&gt;homebrew-cask&lt;/code&gt;, your app has to pass Homebrew's &lt;a href="https://docs.brew.sh/Acceptable-Casks" rel="noopener noreferrer"&gt;cask rules&lt;/a&gt;. It must pass Gatekeeper, work on the latest major macOS, and be notable enough. For a project on GitHub, &lt;a href="https://docs.brew.sh/Package-Acceptance-Policy" rel="noopener noreferrer"&gt;the numbers&lt;/a&gt; are 30 forks, 30 watchers, or 75 stars, rising to 90 forks, 90 watchers, or 225 stars if you submit it yourself. Repositories under 30 days old are normally refused.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your own tap.&lt;/strong&gt; Until then, you can run your own tap, with no one to approve it. That's how Vitals installs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew install --cask foredotstudio/tap/vitals
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. MacBase
&lt;/h2&gt;

&lt;p&gt;This one is mine too. &lt;a href="https://macbase.app" rel="noopener noreferrer"&gt;MacBase&lt;/a&gt; lists only Mac apps, and every listing shows the price, the oldest macOS it runs on, Apple silicon support, and whether it's notarized.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frrytqylio31jmbsw9dpq.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frrytqylio31jmbsw9dpq.webp" alt="The page for Vitals on MacBase, with its icon, price, macOS version, screenshots and member deal" width="800" height="626"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://macbase.app/submit" rel="noopener noreferrer"&gt;Listing is free&lt;/a&gt;. Paste a Mac App Store link, a website, or a GitHub repository, and it fills in a draft, or have your coding agent do it through your &lt;a href="https://macbase.app/mcp" rel="noopener noreferrer"&gt;MCP link&lt;/a&gt;. Put the &lt;a href="https://macbase.app/badge" rel="noopener noreferrer"&gt;badge&lt;/a&gt; on your site, and you get a check mark and a dofollow link.&lt;/p&gt;

&lt;p&gt;Your listing stays up, and it also appears on the &lt;a href="https://macbase.app/alternatives" rel="noopener noreferrer"&gt;alternatives pages&lt;/a&gt; of the well-known apps yours replaces, which is where people arrive ready to switch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiyid01k6u0zcpcaplbnb.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiyid01k6u0zcpcaplbnb.webp" alt="CleanMyMac alternatives on MacBase, with a grid of apps people use instead, and filters for price, open source and Apple silicon" width="800" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're running a sale, add it as a deal too. Right now the &lt;a href="https://macbase.app/deals/black-friday" rel="noopener noreferrer"&gt;Black Friday page&lt;/a&gt; lists deals straight from Mac app makers, with when each one ends.&lt;/p&gt;

&lt;p&gt;It's new, with a Domain Rating of 58, so I can't promise much traffic yet. It's quick to do, which is why it's this high.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Mac press, in any language
&lt;/h2&gt;

&lt;p&gt;Vitals was featured by a Chinese magazine and a Brazilian one, not the English sites you'd pitch first. Vitals is available in both languages, so if your app is translated, look beyond the US press.&lt;/p&gt;

&lt;p&gt;English sites like &lt;a href="https://www.macstories.net" rel="noopener noreferrer"&gt;MacStories&lt;/a&gt; are still worth a try, since a mention there reaches people who care about good Mac software. Nothing is guaranteed, and writers get many pitches.&lt;/p&gt;

&lt;p&gt;Keep your email short: what the app does in one sentence, why it's different, a link, and a free license so they can try it. Write to one person who covers your kind of app, and send it before launch so they have time to look.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. AlternativeTo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://alternativeto.net" rel="noopener noreferrer"&gt;AlternativeTo&lt;/a&gt; is where people go when they want to replace an app. Developers can add their own: sign up, choose Suggest new application from the account menu, and fill in the details. It's &lt;a href="https://alternativeto.net/faq" rel="noopener noreferrer"&gt;checked before it goes live&lt;/a&gt;. I submitted Vitals, and it's live.&lt;/p&gt;

&lt;p&gt;List the well-known apps yours replaces, since that's what puts you in front of people.&lt;/p&gt;

&lt;h2&gt;
  
  
  11. Mac Menu Bar
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://macmenubar.com" rel="noopener noreferrer"&gt;Mac Menu Bar&lt;/a&gt; is a hand-reviewed directory of over 1,500 menu bar apps, sorted into collections like window managers and clipboard managers. &lt;a href="https://macmenubar.com/vitals/" rel="noopener noreferrer"&gt;Vitals is live there&lt;/a&gt;. If your app lives in the menu bar, it's one of the closest fits on this list. If it doesn't, skip this one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://macmenubar.com/submit-your-menu-bar-app/" rel="noopener noreferrer"&gt;The form&lt;/a&gt; asks for at least three screenshots showing the app in the real menu bar, not mockups, so take those first. Search the site before you submit, in case it's already listed.&lt;/p&gt;

&lt;h2&gt;
  
  
  12. MacUpdate
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.macupdate.com" rel="noopener noreferrer"&gt;MacUpdate&lt;/a&gt; has listed Mac software since 1997 and is still updated daily. It's a strong site with a Domain Rating of 77, and it covers nothing but Mac apps. &lt;a href="https://www.macupdate.com/content/submit" rel="noopener noreferrer"&gt;Add your app&lt;/a&gt; with its form, and keep the version current. Review can take a while, so don't leave it until launch day.&lt;/p&gt;

&lt;h2&gt;
  
  
  13. Setapp
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://setapp.com/developers" rel="noopener noreferrer"&gt;Setapp&lt;/a&gt; is a subscription bundle of Mac apps, so it's a sales channel more than a launch. It asks for mature apps with an excellent reputation and stable performance, and it favors apps that fill a gap in a category, so apply once yours has a track record.&lt;/p&gt;

&lt;p&gt;For apps sold singly, Setapp takes 15% of subscriptions and 25% of one-time sales. In the membership, revenue is shared by usage, with Setapp taking 10% and up to 20% going to partners who bring in users.&lt;/p&gt;

&lt;h2&gt;
  
  
  14. Awesome lists on GitHub
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/jaywcjlove/awesome-mac" rel="noopener noreferrer"&gt;awesome-mac&lt;/a&gt; is a curated list of macOS software with about 119,000 stars. If your app is open source, &lt;a href="https://github.com/serhii-londar/open-source-mac-os-apps" rel="noopener noreferrer"&gt;open-source-mac-os-apps&lt;/a&gt; has about 51,000 more. Developers browse these, and lists like them get copied around the web. Read the contributing notes first, then open a pull request adding your app in the right section.&lt;/p&gt;

&lt;h2&gt;
  
  
  15. Macfolio
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://macfolio.com" rel="noopener noreferrer"&gt;Macfolio&lt;/a&gt; is a small curated site for Mac apps, gear, and setups, with some iPhone and iPad apps too. It has a Submit link in its menu. It's worth a few minutes if your app looks good, since the site is built around design.&lt;/p&gt;

&lt;h2&gt;
  
  
  16. Mac App Index
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://macappindex.com" rel="noopener noreferrer"&gt;Mac App Index&lt;/a&gt; is a newer directory of about 240 hand-picked Mac apps, ranked by upvotes. &lt;a href="https://macappindex.com/submit" rel="noopener noreferrer"&gt;Free listings&lt;/a&gt; go live after a quick review. It's small, so treat it as one more place to be found.&lt;/p&gt;

&lt;h2&gt;
  
  
  17. dotstore
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dotstore.io" rel="noopener noreferrer"&gt;dotstore&lt;/a&gt; is a store for web apps, AI agents, and Mac and Windows apps. Its home page says it has over 100,000 apps, and it's &lt;a href="https://dotstore.io/submit" rel="noopener noreferrer"&gt;free for makers&lt;/a&gt;. With that many apps of every kind, yours can get lost, so don't expect much from it.&lt;/p&gt;

&lt;h2&gt;
  
  
  18. Mac App Supply
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://macapp.supply" rel="noopener noreferrer"&gt;Mac App Supply&lt;/a&gt; is one of the best-looking directories on this list: a curated shelf of well-designed macOS apps, each reviewed by hand. It suits an app whose design you're proud of. Its &lt;a href="https://macapp.supply/guidelines" rel="noopener noreferrer"&gt;guidelines&lt;/a&gt; ask for a native macOS app with clean branding, a sharp icon, quality screenshots, and a polished experience, and it rejects web-only and iPhone-only tools. Get those right before you &lt;a href="https://macapp.supply/submit" rel="noopener noreferrer"&gt;submit&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  19. TryMacApps
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.trymacapps.com" rel="noopener noreferrer"&gt;TryMacApps&lt;/a&gt; lists about 330 Mac apps shared by their makers, and at a Domain Rating of 66, it's the strongest of the newer directories. &lt;a href="https://www.trymacapps.com/submit" rel="noopener noreferrer"&gt;Submitting is free&lt;/a&gt; if you put its badge on your landing page, which gets you a permanent listing and a backlink. Editor's Choice costs $39 for top placement for a week.&lt;/p&gt;

&lt;h2&gt;
  
  
  20. MacNative
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://macnative.io" rel="noopener noreferrer"&gt;MacNative&lt;/a&gt; is a curated directory of about 340 native Mac apps, and it's strict about the word. The app must be native or compiled to a native binary, with no browser wrappers, and it needs thoughtful macOS design and active maintenance. Each app is tested by hand, so &lt;a href="https://macnative.io/submit" rel="noopener noreferrer"&gt;review&lt;/a&gt; can take a while, though a paid Pro option is reviewed first. Every listing gets a dofollow link to your site.&lt;/p&gt;

&lt;h2&gt;
  
  
  21. Mac Menubar Apps
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://macmenubar.app" rel="noopener noreferrer"&gt;Mac Menubar Apps&lt;/a&gt; is a second directory for menu bar apps, separate from Mac Menu Bar at number 11, with several hundred listed and a Submit link in its menu. If your app lives in the menu bar, list it on both.&lt;/p&gt;

&lt;h2&gt;
  
  
  22. MacAIApps
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.macaiapps.com" rel="noopener noreferrer"&gt;MacAIApps&lt;/a&gt; is a directory of about 670 Mac apps that use AI, from dictation to coding. &lt;a href="https://www.macaiapps.com/submit" rel="noopener noreferrer"&gt;Listings are free&lt;/a&gt; and reviewed by hand. If your app doesn't use AI, skip it.&lt;/p&gt;

&lt;h2&gt;
  
  
  23. PayOnceApps
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://payonceapps.com" rel="noopener noreferrer"&gt;PayOnceApps&lt;/a&gt; lists web, Windows, and Mac apps you buy once, for people tired of subscriptions. It isn't only for Mac apps, but if yours is a one-time purchase, this is the audience looking for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I left out
&lt;/h2&gt;

&lt;p&gt;General launch sites like Uneed and BetaList take every kind of product. They aren't bad, but few people there are looking for a Mac app, so I'd do everything above first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with a low price
&lt;/h2&gt;

&lt;p&gt;If the price makes people hesitate, it matters less where you launch. Vitals launched at $5, and its price rose in steps as licenses sold. The first 1,000 went at $5 in eight days, and the next 100 were $9.&lt;/p&gt;

&lt;p&gt;I think that was a good decision. It got the app onto a lot of Macs early, and it brought quality feedback when I could still act on it. The site showed how many licenses were left at each price, counted from real sales rather than a timer.&lt;/p&gt;

&lt;p&gt;A sale works the same way later on. For Black Friday, Vitals is $12.99 instead of $49, and Levers and SoundBar are $6.99 instead of $29, until December 5. If you want to run one, I wrote up &lt;a href="https://macbase.app/blog/black-friday-sale-mac-app" rel="noopener noreferrer"&gt;how to run a Black Friday sale for your Mac app&lt;/a&gt;: how much to take off, and how to set it up in Paddle, Lemon Squeezy, Gumroad and the Mac App Store.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to run the launch
&lt;/h2&gt;

&lt;p&gt;Don't do all 23 on one day. You won't be able to answer everyone, and you'd learn nothing about what worked.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Two weeks or more before:&lt;/strong&gt; if you're on the Mac App Store, nominate your app for featuring.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The week before:&lt;/strong&gt; list on the directories that take time to review, like MacBase, AlternativeTo, MacUpdate, Mac Menu Bar, Mac App Supply, and MacNative. Send your press emails.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Launch day:&lt;/strong&gt; post on X, pick one big place (Product Hunt or Show HN), and stay with it all day.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The week after:&lt;/strong&gt; launch on StartupBase, and post in r/macapps with what you changed from that first feedback, which gives people more to talk about.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The months after:&lt;/strong&gt; keep shipping, and share every update on X. Apply to Setapp and the main Homebrew list once you qualify.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Add a &lt;code&gt;?ref=&lt;/code&gt; to your links where you can, so you can see which places sent people who actually bought.&lt;/p&gt;

&lt;p&gt;If you've made a Mac app, you can start now: &lt;a href="https://macbase.app/submit" rel="noopener noreferrer"&gt;list it on MacBase&lt;/a&gt;. It's free.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post first appeared on &lt;a href="https://macbase.app/blog/best-places-to-promote-your-mac-app" rel="noopener noreferrer"&gt;MacBase&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>macos</category>
      <category>marketing</category>
      <category>sideprojects</category>
      <category>showdev</category>
    </item>
    <item>
      <title>After 9 years and nearly 10k listings, I rebuilt StartupBase</title>
      <dc:creator>Atta 🐬</dc:creator>
      <pubDate>Mon, 01 Jun 2026 19:55:58 +0000</pubDate>
      <link>https://dev.to/attacomsian/introducing-startupbase-2-288p</link>
      <guid>https://dev.to/attacomsian/introducing-startupbase-2-288p</guid>
      <description>&lt;p&gt;Nine years ago, in 2017, I launched &lt;a href="https://startupbase.io/" rel="noopener noreferrer"&gt;StartupBase&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At the time, it was a simple side project built around a simple belief:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Great products deserve a better way to get discovered.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Back then, product launches were already becoming crowded. Founders were spending months building products, only to get a brief moment of attention before disappearing into the noise.&lt;/p&gt;

&lt;p&gt;I thought there had to be a better way.&lt;/p&gt;

&lt;p&gt;So I built StartupBase.&lt;/p&gt;

&lt;p&gt;Over the years, something interesting happened.&lt;/p&gt;

&lt;p&gt;Founders kept submitting products.&lt;/p&gt;

&lt;p&gt;Users kept joining.&lt;/p&gt;

&lt;p&gt;The platform slowly grew into nearly &lt;strong&gt;10,000 product listings&lt;/strong&gt; and &lt;strong&gt;13,500+ users&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Most importantly, it helped drive thousands of clicks to products seeking visibility, customers, and feedback.&lt;/p&gt;

&lt;p&gt;That proved something important.&lt;/p&gt;

&lt;p&gt;The problem was real.&lt;/p&gt;

&lt;p&gt;Founders needed better distribution.&lt;/p&gt;

&lt;p&gt;Users wanted better discovery.&lt;/p&gt;

&lt;p&gt;But while StartupBase was useful, I knew it wasn't living up to its full potential.&lt;/p&gt;

&lt;p&gt;The platform had become a victim of its own age.&lt;/p&gt;

&lt;p&gt;The design was dated.&lt;/p&gt;

&lt;p&gt;Product pages lacked depth.&lt;/p&gt;

&lt;p&gt;Discovery could be much better.&lt;/p&gt;

&lt;p&gt;The submission process was slower than it should have been.&lt;/p&gt;

&lt;p&gt;And launches still felt too temporary.&lt;/p&gt;

&lt;p&gt;Products would get attention for a day and then fade away.&lt;/p&gt;

&lt;p&gt;For a long time, I kept pushing improvements down the roadmap.&lt;/p&gt;

&lt;p&gt;Then, eventually, I stopped asking how to patch the old platform and started asking a different question:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What would StartupBase look like if I built it today?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That question became StartupBase 2.&lt;/p&gt;

&lt;p&gt;Not a redesign.&lt;/p&gt;

&lt;p&gt;Not a facelift.&lt;/p&gt;

&lt;p&gt;A complete rebuild.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building StartupBase 2
&lt;/h2&gt;

&lt;p&gt;The goal was not to add features for the sake of adding features.&lt;/p&gt;

&lt;p&gt;The goal was to make StartupBase more useful.&lt;/p&gt;

&lt;p&gt;More useful for founders.&lt;/p&gt;

&lt;p&gt;More useful for users.&lt;/p&gt;

&lt;p&gt;More useful for discovering products worth paying attention to.&lt;/p&gt;

&lt;p&gt;Every major decision came back to those principles.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgy57noy19pqt21labkiy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgy57noy19pqt21labkiy.png" alt="StartupBase v2" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Better product pages
&lt;/h2&gt;

&lt;p&gt;Products deserve more than a logo, a tagline, and a few links.&lt;/p&gt;

&lt;p&gt;StartupBase 2 gives founders richer product pages with more context, media, launch history, team information, and supporting details.&lt;/p&gt;

&lt;p&gt;The goal is simple:&lt;/p&gt;

&lt;p&gt;Help visitors understand a product faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  Discovery beyond launch day
&lt;/h2&gt;

&lt;p&gt;One thing always bothered me about product launches.&lt;/p&gt;

&lt;p&gt;A founder can spend months building something, launch it, and then watch the attention disappear in 24 hours.&lt;/p&gt;

&lt;p&gt;That never felt right.&lt;/p&gt;

&lt;p&gt;StartupBase 2 places much greater emphasis on ongoing discovery through &lt;a href="https://startupbase.io/launches" rel="noopener noreferrer"&gt;daily launches&lt;/a&gt;, weekly and monthly rankings, &lt;a href="https://startupbase.io/collections" rel="noopener noreferrer"&gt;collections&lt;/a&gt;, and topics.&lt;/p&gt;

&lt;p&gt;A good product should continue getting discovered long after launch day.&lt;/p&gt;

&lt;h2&gt;
  
  
  AI Launch Assistant
&lt;/h2&gt;

&lt;p&gt;This is probably my favorite addition.&lt;/p&gt;

&lt;p&gt;Submitting a product can be surprisingly tedious.&lt;/p&gt;

&lt;p&gt;Founders already have enough work to do.&lt;/p&gt;

&lt;p&gt;So we built an AI Launch Assistant that can collect information about a product from across the web and help create a ready-to-submit listing in seconds.&lt;/p&gt;

&lt;p&gt;Instead of filling out everything manually, founders can start with a much better foundation.&lt;/p&gt;

&lt;p&gt;We also use AI to help review submissions and determine whether they are a good fit for StartupBase.&lt;/p&gt;

&lt;p&gt;It is not perfect.&lt;/p&gt;

&lt;p&gt;Sometimes it gets things wrong.&lt;/p&gt;

&lt;p&gt;Oops. 👀&lt;/p&gt;

&lt;p&gt;But it makes the process dramatically faster and helps founders get answers much sooner.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reviews and community feedback
&lt;/h2&gt;

&lt;p&gt;Discovery is better when there is context.&lt;/p&gt;

&lt;p&gt;StartupBase 2 expands reviews and comments so founders can gather feedback and users can make better decisions.&lt;/p&gt;

&lt;p&gt;Products are easier to evaluate when real people can share their experiences.&lt;/p&gt;

&lt;h2&gt;
  
  
  A blog, finally
&lt;/h2&gt;

&lt;p&gt;For years, StartupBase was mostly about launches.&lt;/p&gt;

&lt;p&gt;I wanted it to become more than that.&lt;/p&gt;

&lt;p&gt;With StartupBase 2, we are launching a dedicated &lt;a href="https://startupbase.io/blog" rel="noopener noreferrer"&gt;blog&lt;/a&gt; where I can share launch strategies, growth ideas, founder stories, product updates, and useful resources for builders.&lt;/p&gt;

&lt;p&gt;Launching a product is only one part of the journey.&lt;/p&gt;

&lt;p&gt;Learning how to grow it is another.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simpler onboarding
&lt;/h2&gt;

&lt;p&gt;One small improvement that makes a surprisingly big difference:&lt;/p&gt;

&lt;p&gt;You can now sign in using Google, LinkedIn, or X.&lt;/p&gt;

&lt;p&gt;Previously, X was the only option.&lt;/p&gt;

&lt;p&gt;Getting started should not be harder than it needs to be.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters
&lt;/h2&gt;

&lt;p&gt;At its core, StartupBase 2 is about one thing:&lt;/p&gt;

&lt;p&gt;Helping great products get discovered.&lt;/p&gt;

&lt;p&gt;That mission has not changed since 2017.&lt;/p&gt;

&lt;p&gt;The tools are better.&lt;/p&gt;

&lt;p&gt;The platform is stronger.&lt;/p&gt;

&lt;p&gt;The experience is cleaner.&lt;/p&gt;

&lt;p&gt;But the mission is the same.&lt;/p&gt;

&lt;p&gt;I want founders to have a place where they can launch with confidence.&lt;/p&gt;

&lt;p&gt;And I want users to have a place where they can consistently discover products worth trying.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next?
&lt;/h2&gt;

&lt;p&gt;StartupBase 2 is not the finish line.&lt;/p&gt;

&lt;p&gt;It is the foundation.&lt;/p&gt;

&lt;p&gt;There is still a lot I want to build.&lt;/p&gt;

&lt;p&gt;Better discovery.&lt;/p&gt;

&lt;p&gt;Better founder tools.&lt;/p&gt;

&lt;p&gt;More visibility opportunities.&lt;/p&gt;

&lt;p&gt;Smarter recommendations.&lt;/p&gt;

&lt;p&gt;More ways for products to reach the right audience.&lt;/p&gt;

&lt;p&gt;This release simply gives us a much stronger base to build from.&lt;/p&gt;

&lt;p&gt;If you've been part of the StartupBase journey over the years, thank you. 🙌&lt;/p&gt;

&lt;p&gt;And if you're discovering StartupBase for the first time, welcome. 👋&lt;/p&gt;

&lt;p&gt;And if you have a product to share, you can &lt;a href="https://startupbase.io/submit" rel="noopener noreferrer"&gt;submit it here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>startupbase</category>
      <category>productlaunch</category>
      <category>startup</category>
    </item>
    <item>
      <title>How to implement Stripe revenue verification?</title>
      <dc:creator>Atta 🐬</dc:creator>
      <pubDate>Sun, 05 Sep 2021 17:59:09 +0000</pubDate>
      <link>https://dev.to/attacomsian/how-to-implement-stripe-revenue-verification-21nd</link>
      <guid>https://dev.to/attacomsian/how-to-implement-stripe-revenue-verification-21nd</guid>
      <description>&lt;p&gt;I am building &lt;a href="https://acquirebase.com" rel="noopener noreferrer"&gt;AcquireBase&lt;/a&gt; - a marketplace for buying and selling side-projects, micro-SaaS, etc.&lt;/p&gt;

&lt;p&gt;As part of our upcoming feature, we want to allow our seller to verify their reported MRR via Stripe - something IH already does for products.&lt;/p&gt;

&lt;p&gt;It has been over 1 month since I am trying to figure out how to do this. I tried Google search but nothing came up useful. Stripe's documentation did help either. &lt;/p&gt;

&lt;p&gt;Now, I'm getting frustrated. &lt;/p&gt;

&lt;p&gt;Is there anyone who has successfully implemented Stripe revenue verification or knows how to do this? &lt;/p&gt;

&lt;p&gt;I'd highly appreciate it if you share the info with me.&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;

</description>
      <category>help</category>
    </item>
    <item>
      <title>Are Ad Blockers blocking Google Analytics?</title>
      <dc:creator>Atta 🐬</dc:creator>
      <pubDate>Tue, 03 Mar 2020 11:03:37 +0000</pubDate>
      <link>https://dev.to/attacomsian/are-ad-blockers-blocking-google-analytics-1e5j</link>
      <guid>https://dev.to/attacomsian/are-ad-blockers-blocking-google-analytics-1e5j</guid>
      <description>&lt;p&gt;&lt;a href="https://attacomsian.com/blog" rel="noopener noreferrer"&gt;Blog&lt;/a&gt; Stats Discrepancy (Feb 2020)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Google Analytics shows I had &lt;strong&gt;70.7k&lt;/strong&gt; total users including direct, organic, referrals, and social.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Google Search Console displays I had &lt;strong&gt;81.7K&lt;/strong&gt; organic clicks only in the month of February.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, I am wondering what went wrong with GA tracking. Are Ad Blockers the real culprit?&lt;/p&gt;

&lt;p&gt;Does anyone know how to bypass Ad Blockers?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>help</category>
    </item>
    <item>
      <title>Introduction to JavaScript URL Object</title>
      <dc:creator>Atta 🐬</dc:creator>
      <pubDate>Sun, 08 Sep 2019 14:58:53 +0000</pubDate>
      <link>https://dev.to/attacomsian/introduction-to-javascript-url-object-27hn</link>
      <guid>https://dev.to/attacomsian/introduction-to-javascript-url-object-27hn</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was originally published on &lt;a href="https://attacomsian.com/blog/javascript-url-object" rel="noopener noreferrer"&gt;attacomsian.com/blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;The vanilla JavaScript &lt;code&gt;URL&lt;/code&gt; object is used to parse, construct, normalize, and encode URLs. It provides static methods and properties to easily read and modify different components of the URL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a URL
&lt;/h2&gt;

&lt;p&gt;You can create a new &lt;code&gt;URL&lt;/code&gt; object by either passing the string URL or by providing a relative path and a base string URL to its constructor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// url object with absolute path&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;url1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://attacomsian.com/blog/javascript-url-object'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// url object with relative path and base url&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;url2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/blog/javascript-url-object'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'https://attacomsian.com'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, both URLs are same. We can even create a new URL based on the path relative to an existing URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// create new url based on existing url&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;url3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/blog'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// https://atttacomsian.com/blog&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  URL Properties
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;URL&lt;/code&gt; object is very helpful if you want to extract different parts from a string URL, such as the host name, port, relative path, and parameter values. You can access these &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/URL#Properties" rel="noopener noreferrer"&gt;properties&lt;/a&gt; immediately after the &lt;code&gt;URL&lt;/code&gt; object is created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://attacomsian.com/blog/javascript-url-object#url-properties'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;protocol&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// https:&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;// attacomsian.com&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// /blog/javascript-url-object&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;// #url-properties&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// https://attacomsian.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In addition to the above properties, the &lt;code&gt;URL&lt;/code&gt; object also has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;search&lt;/code&gt; — The query parameters string including the leading &lt;code&gt;?&lt;/code&gt; character.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;href&lt;/code&gt; — The complete URL, same as &lt;code&gt;url.toString()&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;port&lt;/code&gt; — Returns the port of the URL.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;searchParams&lt;/code&gt; — A &lt;code&gt;URLSearchParams&lt;/code&gt; object that can be used to access the individual query parameters found in &lt;code&gt;search&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;username&lt;/code&gt; &amp;amp; &lt;code&gt;password&lt;/code&gt; — Only available if HTTP authentication is used.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Apart from the above properties, the &lt;code&gt;URL&lt;/code&gt; object also provides two methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;toString()&lt;/code&gt; — It is similar to &lt;code&gt;url.href&lt;/code&gt; but cannot be used to modify the value.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toJSON()&lt;/code&gt; — It returns the same string as &lt;code&gt;href&lt;/code&gt; property.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Updating a URL
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;URL&lt;/code&gt; object properties (except &lt;code&gt;origin&lt;/code&gt; and &lt;code&gt;searchParams&lt;/code&gt;) can be used to construct a new URL or update parts of an existing URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// construct a url&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'http://attacomsian.com'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pathname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'/blog/javascript-url-object'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'#url-properties'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// update `protocol` property&lt;/span&gt;
&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;protocol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'https:'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// https://attacomsian.com/blog/javascript-url-object#url-properties&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Static Methods
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;URL&lt;/code&gt; interface provides &lt;code&gt;createObjectURL()&lt;/code&gt; static method to generate a blob URL (starts with &lt;code&gt;blob:&lt;/code&gt; as its schema) that uniquely identify the object in the browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;blobUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createObjectURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have the blob URL, pass it to &lt;code&gt;revokeObjectURL()&lt;/code&gt; static method to remove it from the memory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;revokeObjectURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blobUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  URL Object Usage
&lt;/h2&gt;

&lt;p&gt;At the moment, the &lt;code&gt;URL&lt;/code&gt; object usage is limited. Simple strings are good enough for making network requests. However, you can use the &lt;code&gt;URL&lt;/code&gt; object in modern JavaScript APIs especially in &lt;a href="https://attacomsian.com/blog/javascript-fetch-api" rel="noopener noreferrer"&gt;Fetch API&lt;/a&gt;, or even in &lt;a href="https://attacomsian.com/blog/http-requests-xhr" rel="noopener noreferrer"&gt;XMLHttpRequest  (XHR)&lt;/a&gt; to communicate with the server. &lt;/p&gt;

&lt;p&gt;Here is an example of Fetch API that uses a &lt;code&gt;URL&lt;/code&gt; object to get a JSON object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://reqres.in/api/users'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${user.id}: ${user.first_name} ${user.last_name}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;✌️ I write about &lt;strong&gt;modern JavaScript, Node.js, Spring Boot&lt;/strong&gt;, and all things &lt;strong&gt;web development&lt;/strong&gt;. &lt;a href="https://attacomsian.com/newsletter" rel="noopener noreferrer"&gt;&lt;strong&gt;Subscribe to my newsletter&lt;/strong&gt;&lt;/a&gt; to get web development tutorials &amp;amp; protips every week.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Like this article?&lt;/strong&gt; &lt;a href="https://twitter.com/attacomsian" rel="noopener noreferrer"&gt;Follow @attacomsian on Twitter&lt;/a&gt;. You can also follow me on &lt;a href="https://linkedin.com/in/attacomsian" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; and &lt;a href="https://dev.to/attacomsian"&gt;DEV&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Object.entries() and Object.values() Methods in JavaScript</title>
      <dc:creator>Atta 🐬</dc:creator>
      <pubDate>Thu, 22 Aug 2019 16:21:29 +0000</pubDate>
      <link>https://dev.to/attacomsian/object-entries-and-object-values-methods-in-javascript-3l8c</link>
      <guid>https://dev.to/attacomsian/object-entries-and-object-values-methods-in-javascript-3l8c</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was originally published on &lt;a href="https://attacomsian.com/blog/object-entries-values-javascript" rel="noopener noreferrer"&gt;attacomsian.com/blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;The &lt;code&gt;Object.entries()&lt;/code&gt; and &lt;code&gt;Object.values()&lt;/code&gt; methods were introduced to JavaScript &lt;code&gt;Object&lt;/code&gt; constructor with the release of ECMAScript 2017 (ES8). Let us have a quick look at these useful methods.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;Object.entries()&lt;/code&gt; Method
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Object.entries()&lt;/code&gt; method takes an object as argument and returns an array with arrays of key-value pairs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;birds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;owl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'🦉'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;eagle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'🦅'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;duck&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'🦆'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;entries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;birds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// [['owl', '🦉'], ['eagle', '🦅'], ['duck', '🦆']]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The order of the array element do not depend on how the object was defined. The order is same as that provided by a &lt;code&gt;for...in&lt;/code&gt; loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Iterating through an Object
&lt;/h3&gt;

&lt;p&gt;We can use &lt;code&gt;Object.entries()&lt;/code&gt; to iterate over object as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// using `for...of` loop&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;birds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${key}: ${value}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// owl: 🦉&lt;/span&gt;
&lt;span class="c1"&gt;// eagle: 🦅&lt;/span&gt;
&lt;span class="c1"&gt;// duck: 🦆&lt;/span&gt;

&lt;span class="c1"&gt;// using array destructuring&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;birds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${key}: ${value}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// owl: 🦉&lt;/span&gt;
&lt;span class="c1"&gt;// eagle: 🦅&lt;/span&gt;
&lt;span class="c1"&gt;// duck: 🦆&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Converting an Object to a Map
&lt;/h3&gt;

&lt;p&gt;Since the &lt;a href="https://attacomsian.com/blog/maps-javascript#initialize-a-map" rel="noopener noreferrer"&gt;Map constructor&lt;/a&gt; also takes an iterable of &lt;code&gt;entries&lt;/code&gt; to initialize a map object, the &lt;code&gt;Object.entries()&lt;/code&gt; method can be used to create a map from an object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;birds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;span class="n"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'owl'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="n"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'duck'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 🦆&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;Object.values()&lt;/code&gt; Method
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Object.values()&lt;/code&gt; method works very much like &lt;code&gt;Object.entries()&lt;/code&gt;, but only returns the values of the own enumerable string-keyed properties in the same order as provided by the &lt;code&gt;for...in&lt;/code&gt; loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;foods&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;cake&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'🍰'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;pizza&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'🍕'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;candy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'🍬'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;icecream&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'🍨'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;foods&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// ['🍰', '🍕', '🍬', '🍨']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both &lt;code&gt;Object.values()&lt;/code&gt; and &lt;code&gt;Object.entries()&lt;/code&gt; do not follow the prototype chain and only iterate through the properties that are directly added to the given object. They also ignore all non-enumerable properties as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defineProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;foods&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'sushi'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'🍣'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;writable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;configurable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;enumerable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;foods&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// ['🍰', '🍕', '🍬', '🍨']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Converting an Object to Set
&lt;/h3&gt;

&lt;p&gt;Since the &lt;a href="https://attacomsian.com/blog/sets-javascript#initialize-a-set" rel="noopener noreferrer"&gt;Set constructor&lt;/a&gt; accepts an iterable, with &lt;code&gt;Object.values()&lt;/code&gt;, we can easily convert an &lt;code&gt;Object&lt;/code&gt; to a &lt;code&gt;Set&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;foods&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'🍨'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;✌️ I write about &lt;strong&gt;modern JavaScript, Node.js, Spring Boot&lt;/strong&gt;, and all things &lt;strong&gt;web development&lt;/strong&gt;. &lt;a href="https://attacomsian.com/newsletter" rel="noopener noreferrer"&gt;&lt;strong&gt;Subscribe to my newsletter&lt;/strong&gt;&lt;/a&gt; to get web development tutorials &amp;amp; protips every week.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Like this article?&lt;/strong&gt; &lt;a href="https://twitter.com/attacomsian" rel="noopener noreferrer"&gt;Follow @attacomsian on Twitter&lt;/a&gt;. You can also follow me on &lt;a href="https://linkedin.com/in/attacomsian" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; and &lt;a href="https://dev.to/attacomsian"&gt;DEV&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Introduction to XMLHttpRequest (XHR)</title>
      <dc:creator>Atta 🐬</dc:creator>
      <pubDate>Fri, 16 Aug 2019 11:56:59 +0000</pubDate>
      <link>https://dev.to/attacomsian/introduction-to-xmlhttprequest-xhr-142j</link>
      <guid>https://dev.to/attacomsian/introduction-to-xmlhttprequest-xhr-142j</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was originally published on &lt;a href="https://attacomsian.com/blog/http-requests-xhr" rel="noopener noreferrer"&gt;attacomsian.com/blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;XMLHttpRequest (XHR) was invented by Microsoft in the early '90s and became a go-to technology for asynchronous server interactions during the mid of the first decade of the 21st century. &lt;/p&gt;

&lt;p&gt;Thanks to XHR, for the first time, it became possible to update parts of a web page without reloading the whole page.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;XMLHttpRequest&lt;/code&gt; is a built-in browser object in all modern browsers that can be used to make HTTP requests in JavaScript to exchange data between the web browser and the server.&lt;/p&gt;

&lt;p&gt;Despite the word "XML" in its name, &lt;code&gt;XMLHttpRequest&lt;/code&gt; can be used to retrieve any kind of data, and not just XML. We can use it to upload/download files, submit form data, track progress and much more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic XHR Request
&lt;/h2&gt;

&lt;p&gt;To send an HTTP request using XHR, create an &lt;code&gt;XMLHttpRequest&lt;/code&gt; object, open a connection to URL, and send the request. Once the request completes, the object will contain useful information such as the response body and the HTTP status code.&lt;/p&gt;

&lt;p&gt;Let's use &lt;a href="https://jsonplaceholder.typicode.com/" rel="noopener noreferrer"&gt;JSONPlaceholder&lt;/a&gt; test REST API to send a GET request using XHR:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// create an XHR object&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;xhr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;XMLHttpRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// listen for `onload` event&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// process response&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// parse JSON data&lt;/span&gt;
        &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Error!'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// create a `GET` request&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'GET'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'https://jsonplaceholder.typicode.com/users'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// send request&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;xhr.onload&lt;/code&gt; event only works in modern browsers (IE10+, FireFox, Chrome, Safari). If you want to support old browsers, use &lt;code&gt;xhr.onreadystatechange&lt;/code&gt; event instead.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;xhr.open()&lt;/code&gt; Method
&lt;/h2&gt;

&lt;p&gt;In the example above, we passed the HTTP method and a URL to the request to &lt;code&gt;open()&lt;/code&gt; method. This method is normally called right after &lt;code&gt;new XMLHttpRequest()&lt;/code&gt;. We can use this method to specify the main parameters of the request:&lt;/p&gt;

&lt;p&gt;Here is the syntax of this method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;method&lt;/code&gt; — HTTP request method. It can be &lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;DELETE&lt;/code&gt;, &lt;code&gt;PUT&lt;/code&gt;, etc.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;URL&lt;/code&gt; — The URL to request, a string or a &lt;a href="https://attacomsian.com/blog/javascript-url-object" rel="noopener noreferrer"&gt;URL object&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;asnyc&lt;/code&gt; — Specify whether the request should be made asynchronously or not. Default value is &lt;code&gt;true&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;username&lt;/code&gt; &amp;amp; &lt;code&gt;password&lt;/code&gt; — Credentials for basic HTTP authentication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;open()&lt;/code&gt; method does not open the connection to URL. It only configures the HTTP request. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;xhr.send()&lt;/code&gt; Method
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;send()&lt;/code&gt; method opens the network connection and sends the request to the server. It takes an optional &lt;code&gt;body&lt;/code&gt; parameter that contains the request body. For request methods like &lt;code&gt;GET&lt;/code&gt; you do not need to pass the body parameter.&lt;/p&gt;

&lt;h2&gt;
  
  
  XHR Events
&lt;/h2&gt;

&lt;p&gt;The three most widely used XHR events are the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;load&lt;/code&gt; — This event is called when the result is ready. It is equivalent to &lt;code&gt;xhr.onreadystatechange&lt;/code&gt; event with &lt;code&gt;xhr.readyState == 4&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;error&lt;/code&gt; — This event is fired when the request is failed due to network down or invalid URL.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;progress&lt;/code&gt; — This event is triggered periodically during the response download. It can be used to report progress for large network requests.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// listen for `load` event&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`Data Loaded: ${xhr.status} ${xhr.response}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// listen for `error` event&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onerror&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Request failed.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// listen for `progress` event&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onprogress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// event.loaded returns how many bytes are downloaded&lt;/span&gt;
    &lt;span class="c1"&gt;// event.total returns the total number of bytes&lt;/span&gt;
    &lt;span class="c1"&gt;// event.total is only available if server sends `Content-Length` header&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`Downloaded ${event.loaded} of ${event.total}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Request Timeout
&lt;/h2&gt;

&lt;p&gt;You can easily configure the request timeout by specify the time in milliseconds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// set timeout&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 5 seconds&lt;/span&gt;

&lt;span class="c1"&gt;// listen for `timeout` event&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ontimeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Request timeout.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;responseURL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;xhr.responseURL&lt;/code&gt; property returns the final URL of a &lt;code&gt;XMLHttpRequest&lt;/code&gt; instance after following all redirects. This is the only way to retrieve &lt;code&gt;Location&lt;/code&gt; header.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Response Type
&lt;/h2&gt;

&lt;p&gt;We can use &lt;code&gt;xhr.responseType&lt;/code&gt; property to set the expected response format:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Empty (default) or &lt;code&gt;text&lt;/code&gt; — plain text&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;json&lt;/code&gt; — parsed JSON&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;blob&lt;/code&gt; — binary data Blob&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;document&lt;/code&gt; — XML document&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;arraybuffer&lt;/code&gt; — &lt;code&gt;ArrayBuffer&lt;/code&gt; for binary data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's call a RESTful API to get the response as JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;xhr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;XMLHttpRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'GET'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'https://api.jsonbin.io/b/5d5076e01ec3937ed4d05eab/1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// set response format&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;responseType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'json'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// get JSON response&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// log details&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// John Doe&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// john.doe@example.com&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;website&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// http://example.com&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Request States (&lt;code&gt;xhr.readyState&lt;/code&gt;)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;XMLHttpRequest&lt;/code&gt; object changes state as the request progresses. We can access the current state using &lt;code&gt;xhr.readyState&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;The states are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;UNSENT&lt;/code&gt; (0) — The initial state&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;OPENED&lt;/code&gt; (1) — The request begins&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;HEADERS_RECEIVED&lt;/code&gt; (2) — The HTTP headers received&lt;/li&gt;
&lt;li&gt; &lt;code&gt;LOADING&lt;/code&gt; (3) — Response is loading&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DONE&lt;/code&gt; (4) — The request is completed &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can track the request state by using &lt;code&gt;onreadystatechange&lt;/code&gt; event:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onreadystatechange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;readyState&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Request started.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;readyState&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Headers received.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;readyState&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Data loading..!'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;readyState&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Request ended.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Aborting Request
&lt;/h2&gt;

&lt;p&gt;We can easily abort an XHR request anytime by calling the &lt;code&gt;abort()&lt;/code&gt; method on the &lt;code&gt;xhr&lt;/code&gt; object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// cancel request&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Synchronous Requests
&lt;/h2&gt;

&lt;p&gt;By default, XHR makes asynchronous requests which is good for performance. But if you want to make an explicit synchronous request, just pass &lt;code&gt;false&lt;/code&gt; as 3rd argument to &lt;code&gt;open()&lt;/code&gt; method. It will pause the JavaScript execution at &lt;code&gt;send()&lt;/code&gt; and resume when the response is available:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'GET'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'https://api.jsonbin.io/b/5d5076e01ec3937ed4d05eab/1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Be careful!&lt;/strong&gt; Chrome display the following warning for synchronous XHR request: &lt;em&gt;[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  HTTP Headers
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;XMLHttpRequest&lt;/code&gt; allows us to set request headers as well as read response headers. We can set the request &lt;code&gt;Content-Type&lt;/code&gt; &amp;amp; &lt;code&gt;Accept&lt;/code&gt; headers by calling &lt;code&gt;setRequestHeader()&lt;/code&gt; method on the &lt;code&gt;xhr&lt;/code&gt; object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// set request headers&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setRequestHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setRequestHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Accept'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'*/*'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// accept all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly if you want to read the response headers (except &lt;code&gt;Set-Cookie&lt;/code&gt;), call &lt;code&gt;getResponseHeader()&lt;/code&gt; on the &lt;code&gt;xhr&lt;/code&gt; object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// read response headers&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getResponseHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getResponseHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Cache-Control'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Want to get response headers at once? Use &lt;code&gt;getAllResponseHeaders()&lt;/code&gt; instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAllResponseHeaders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  XHR POST Request
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;XMLHttpRequest&lt;/code&gt; POST request to submit a form data can be sent in two ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using only Ajax&lt;/li&gt;
&lt;li&gt;Using &lt;code&gt;FormData&lt;/code&gt; API&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first approach is good enough unless you want to upload a file and need &lt;code&gt;multipart/form-data&lt;/code&gt; encoding. Here is how we can make a POST request with URL encoded form data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;xhr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;XMLHttpRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// configure a `POST` request&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'POST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'/login'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// prepare form data&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'username=attacomsian&amp;amp;password=123456'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// set `Content-Type` header&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setRequestHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'application/x-www-form-urlencoded'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// pass `params` to `send()` method&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// listen for `load` event&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;responseText&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Want to make a JSON POST request?&lt;/strong&gt; Make sure you convert the JSON data into a string using &lt;a href="https://attacomsian.com/blog/json-parse-stringify#jsonstringify" rel="noopener noreferrer"&gt;JSON.stringify()&lt;/a&gt; and set the &lt;code&gt;Content-Type&lt;/code&gt; header to &lt;code&gt;application/json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;xhr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;XMLHttpRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// configure a `POST` request&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'POST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'/login'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// create a JSON object&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'attacomsian'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'123456'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// set `Content-Type` header&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setRequestHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// pass `params` to `send()` method&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// listen for `load` event&lt;/span&gt;
&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;responseText&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Cross-Origin Requests &amp;amp; Cookies
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;XMLHttpRequest&lt;/code&gt; can send cross-origin requests, but it is subjected to special security measures. To request a resource from a different server, the server must explicitly support this using CORS (Cross-Origin Resource Sharing).&lt;/p&gt;

&lt;p&gt;Just like &lt;a href="https://attacomsian.com/blog/javascript-fetch-api#fetch-and-cookies" rel="noopener noreferrer"&gt;Fetch API&lt;/a&gt;, XHR does not send cookies and HTTP-authorization to another origin. To send cookies, you can use &lt;code&gt;withCredentials&lt;/code&gt; property of the &lt;code&gt;xhr&lt;/code&gt; object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;withCredentials&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  XHR vs jQuery
&lt;/h2&gt;

&lt;p&gt;jQuery wrapper methods like &lt;code&gt;$.ajax()&lt;/code&gt; uses XHR under the hood and provides a higher-level of abstraction to make developers life easy. Using jQuery, we can translate the above code into just a few lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;$&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ajax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://jsonplaceholder.typicode.com/users'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;done&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Error:'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  XHR vs Fetch API
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://attacomsian.com/blog/javascript-fetch-api" rel="noopener noreferrer"&gt;Fetch API&lt;/a&gt; is a &lt;a href="https://attacomsian.com/blog/promises-javascript" rel="noopener noreferrer"&gt;promise-based&lt;/a&gt; modern alternative to XHR. It is clean, easier to understand, and massively used in &lt;a href="https://attacomsian.com/blog/service-workers-javascript" rel="noopener noreferrer"&gt;PWA Service Workers&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The XHR example above can be converted to a much simpler &lt;code&gt;fetch()&lt;/code&gt;-based code that even automatically parses the returned JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://jsonplaceholder.typicode.com/users'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Error:'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;✌️ I write about &lt;strong&gt;modern JavaScript, Node.js, Spring Boot&lt;/strong&gt;, and all things &lt;strong&gt;web development&lt;/strong&gt;. &lt;a href="https://attacomsian.com/newsletter" rel="noopener noreferrer"&gt;&lt;strong&gt;Subscribe to my newsletter&lt;/strong&gt;&lt;/a&gt; to get web development tutorials &amp;amp; protips every week.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Like this article?&lt;/strong&gt; &lt;a href="https://twitter.com/attacomsian" rel="noopener noreferrer"&gt;Follow @attacomsian on Twitter&lt;/a&gt;. You can also follow me on &lt;a href="https://linkedin.com/in/attacomsian" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; and &lt;a href="https://dev.to/attacomsian"&gt;DEV&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Introduction to JavaScript Regular Expressions</title>
      <dc:creator>Atta 🐬</dc:creator>
      <pubDate>Fri, 09 Aug 2019 11:14:32 +0000</pubDate>
      <link>https://dev.to/attacomsian/introduction-to-javascript-regular-expressions-49e2</link>
      <guid>https://dev.to/attacomsian/introduction-to-javascript-regular-expressions-49e2</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was originally published on &lt;a href="https://attacomsian.com/blog/javascript-regular-expressions" rel="noopener noreferrer"&gt;attacomsian.com/blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;A regular expression (also called &lt;strong&gt;regex&lt;/strong&gt; or &lt;strong&gt;regexp&lt;/strong&gt;) is a sequence of characters that defines a search pattern. These search patterns are usually used for &lt;strong&gt;text search&lt;/strong&gt;, &lt;strong&gt;text search and replace&lt;/strong&gt;, &lt;strong&gt;data extraction&lt;/strong&gt;, and &lt;strong&gt;input validation&lt;/strong&gt; operations.&lt;/p&gt;

&lt;p&gt;Just like other programming languages, JavaScript also supports regular expressions to perform pattern-matching and search-and-replace functions on strings. JavaScript treats regular expression as an object with predefined properties and methods.&lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;

&lt;p&gt;A regular expression can consist of one or more metacharacters and literal characters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/pattern/modifiers;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, &lt;code&gt;/javascript/i&lt;/code&gt; is a regular expression where &lt;code&gt;javascript&lt;/code&gt; is a search pattern and &lt;code&gt;i&lt;/code&gt; is a modifier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Regular Expression
&lt;/h2&gt;

&lt;p&gt;In JavaScript, you can create a regular expression in two ways: using a regular expression literal or calling the constructor of &lt;code&gt;RegExp&lt;/code&gt; to initialize a new object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;re1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;script&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;re2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'java+script'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'g'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In literal form, regular expressions are compiled when the script is loaded. If the pattern remains constant, regular expression literals are better in terms of performance.&lt;/p&gt;

&lt;p&gt;On the other hand, regular expressions created using constructor are compiled at runtime and should only be used when you are sure the pattern is dynamic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing a Regular Expression
&lt;/h2&gt;

&lt;p&gt;You can use &lt;code&gt;test()&lt;/code&gt; method of &lt;code&gt;RegExp&lt;/code&gt; object to quickly test a regular expression. This method performs a search for a match between a regular expression and a specified string. It returns &lt;code&gt;true&lt;/code&gt; if a match is found, otherwise &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;script&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;gi&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'javascript'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'JavaScript is a client side programming language'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'java'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another way to test a regular expression is using &lt;code&gt;exec()&lt;/code&gt; method of &lt;code&gt;RegExp&lt;/code&gt; object. It runs a search for a match in the target string and returns an array if found, otherwise &lt;code&gt;null&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/^&lt;/span&gt;&lt;span class="nc"&gt;The&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'The Apple'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// ["The", index: 0, input: "The Apple", groups: undefined]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Regular Expression Modifiers
&lt;/h2&gt;

&lt;p&gt;Modifiers (also called flags) are special characters that can be used to perform case-insensitive more advanced searches.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;i&lt;/code&gt; performs case-insensitive matching&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;g&lt;/code&gt; performs a global match (does not stop after finding the first match and finds all possible matches)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;m&lt;/code&gt; performs multiline matching&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;u&lt;/code&gt; enables unicode characters matching (introduced in ES6)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;s&lt;/code&gt; (also called "dotAll") allows &lt;code&gt;.&lt;/code&gt; to match newlines (introduced in ES9)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Flags can be combined to perform sophisticated matching operations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;re1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;script&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;gi&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;re2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'java+script'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'gi'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Regular Expression Patterns
&lt;/h2&gt;

&lt;p&gt;A regular expression pattern consists of either simple characters such as &lt;code&gt;/javascript/&lt;/code&gt; or a combination of simple and special characters such as &lt;code&gt;/java*script/&lt;/code&gt;. Simple characters are used for direct match. For example, the simple pattern &lt;code&gt;/bcd/&lt;/code&gt; matches characters combinations in strings only when exactly the characters 'bcd' appear together and in exact same order.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bcd&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Who is this bcd?'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// exact match substring bcd&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Special characters are used to match a broad range of values than literal strings. For example, to match a single 'a' followed by one or more 'b's followed by 'd', we can use the pattern &lt;code&gt;/ab+d/&lt;/code&gt;. The &lt;code&gt;+&lt;/code&gt; after 'b' means "1 or more occurrences of the previous item."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ab&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'aabbbdccbbbd'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// match substring abbbd&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following tables provide a complete list of special characters along with examples that can be used in regular expressions:&lt;/p&gt;

&lt;h3&gt;
  
  
  Assertions
&lt;/h3&gt;

&lt;p&gt;Assertions show that a match is possible in some way. Assertions include &lt;strong&gt;look-ahead&lt;/strong&gt;, &lt;strong&gt;look-behind&lt;/strong&gt;, and &lt;strong&gt;conditional expressions&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;?&lt;/code&gt; character can also be used as a quantifier.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Characters&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;x(?=y)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/Atta(?=shah)/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Look-ahead assertion. Matches &lt;code&gt;x&lt;/code&gt; only if it is followed by &lt;code&gt;y&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;x(?!y)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/\d+(?!\.)/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Negative look-ahead assertion. Matches &lt;code&gt;x&lt;/code&gt; only if it is NOT followed by &lt;code&gt;y&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;(?&amp;lt;=y)x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/(?&amp;lt;=shah)Atta/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Look-behind assertion. Matches &lt;code&gt;x&lt;/code&gt; only if it is preceded by &lt;code&gt;y&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;(?&amp;lt;!y)x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/(?&amp;lt;!-)\d+/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Negative look-behind assertion. Matches &lt;code&gt;x&lt;/code&gt; only if it is NOT preceded by &lt;code&gt;y&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In assertions, only the &lt;code&gt;x&lt;/code&gt; is a part of the match. For example, &lt;code&gt;/Europe+(?=Germany|France)/&lt;/code&gt; matches "Europe" only if it is followed by "Germany" or "France". However, neither "Germany" not "France" is part of the match results.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Europe&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;?=&lt;/span&gt;&lt;span class="nc"&gt;Germany&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nc"&gt;France&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'EuropeGermany'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "EuropeGermany"&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;?&amp;lt;!-&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;+/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'45.99'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "45"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Boundaries
&lt;/h3&gt;

&lt;p&gt;Boundaries indicate the starts and ends of lines and words.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Characters&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;^&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/^An/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches the start of input&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/App$/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches the end of input&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/un\b/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches a word boundary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\B&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/\Bon/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches a non-word boundary&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/^&lt;/span&gt;&lt;span class="nc"&gt;An&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'An Apple'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "An"&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;App&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Mobile App'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "App" &lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;un&lt;/span&gt;\&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Sun'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "un"&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="nc"&gt;Bon&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Moon'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "on"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Groups and Ranges
&lt;/h3&gt;

&lt;p&gt;Groups and ranges are useful to find a range of characters.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;(x|y)&lt;/code&gt; matches either &lt;code&gt;x&lt;/code&gt; or &lt;code&gt;y&lt;/code&gt;. For example, &lt;code&gt;/(green|red)/&lt;/code&gt; matches "red" in "red bull".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[abcd]&lt;/code&gt; matches any one of the enclosed characters. Equivalent to &lt;code&gt;[a-d]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[^abcd]&lt;/code&gt; matches none of the enclosed characters. Equivalent to &lt;code&gt;[^a-d]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[0-9]&lt;/code&gt; matches any one of the enclosed characters (any digit).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[^0-9]&lt;/code&gt; matches none of the enclosed characters (any non-digit).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'a2'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "a"&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'a2'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "2"&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;z0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'$a2'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "a"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Character Classes
&lt;/h3&gt;

&lt;p&gt;Character Classes (also called &lt;strong&gt;Metacharacters&lt;/strong&gt;) are characters with special meaning to distinguish kinds of characters. For example, differentiating between letters and digits.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Characters&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/.s/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches any single character, except newline or line terminators&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\w&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/\w/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches any alphanumeric character including underscore. Equivalent to &lt;code&gt;[A-Za-z0-9_]&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\W&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/\W/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches any non-alphanumeric character. Equivalent to &lt;code&gt;[^A-Za-z0-9_]&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\d&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/\d/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches any digit. Equivalent to &lt;code&gt;[0-9]&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\D&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/\D/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches any character that is not a digit. Equivalent to &lt;code&gt;[^0-9]&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\s&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/\s/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches a single whitespace character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\S&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/\S/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches a single character other than whitespace&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\t&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/\t/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches a tab character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\n&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/\n/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches a newline character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/\0/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches a NUL character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\uxxxx&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/\uxxxx/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches a unicode character&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'yes'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "es"&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'3D'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "3"&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'$9.99'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "9"&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="no"&gt;W&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'45%'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "%"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Quantifiers
&lt;/h3&gt;

&lt;p&gt;Quantifiers define quantities and indicate numbers of characters or expressions to match.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Characters&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;n+&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/ab+/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches any string that contains at least one &lt;code&gt;n&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;n*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/ab*/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches any string that contains zero or more occurrences of &lt;code&gt;n&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;n?&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/ab?/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches any string that contains zero or one &lt;code&gt;n&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;n{x}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/a{2}/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches exactly &lt;code&gt;x&lt;/code&gt; occurrences of the preceding item &lt;code&gt;n&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;n{x,}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/a{2, }/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches at least &lt;code&gt;x&lt;/code&gt; occurrences of the preceding item &lt;code&gt;n&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;n{x,y}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/a{1,3}/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches at least &lt;code&gt;x&lt;/code&gt; and at most &lt;code&gt;y&lt;/code&gt; occurrences of the preceding item &lt;code&gt;n&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ab&lt;/span&gt;&lt;span class="o"&gt;+/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'abbcdab'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "abb"&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bb&lt;/span&gt;&lt;span class="o"&gt;*/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'abbcdab'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "bb"&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'abbcdab'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "bb"&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'bbcdaaab'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// matches "aaa"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Regular Expression Escaping
&lt;/h2&gt;

&lt;p&gt;If you want to use any of the special characters as literals (like searching for a '+'), you need to escape them by putting a backslash in front of them. For instance, to search for 'a' followed by '+' followed by 'c', you'd use &lt;code&gt;/a\+b/&lt;/code&gt;. The backslash "escapes" the '+', making it literal instead of special.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;\&lt;span class="o"&gt;+&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2+2'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;\$\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'$2.49'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Regular Expression Usage
&lt;/h2&gt;

&lt;p&gt;In JavaScript, regular expressions are used with &lt;code&gt;RegExp&lt;/code&gt;'s object method &lt;code&gt;exec()&lt;/code&gt; and &lt;code&gt;test()&lt;/code&gt;, and with the &lt;code&gt;match()&lt;/code&gt;, &lt;code&gt;replace()&lt;/code&gt;, &lt;code&gt;search()&lt;/code&gt;, and &lt;code&gt;split()&lt;/code&gt; methods of &lt;code&gt;String&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"JavaScript is a client-side programming language"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//16 (the starting position of "client")&lt;/span&gt;
&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'server'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//JavaScript is a server-side programming language&lt;/span&gt;
&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//["client", index: 16]&lt;/span&gt;
&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//["JavaScript", "is", "a", "client-side", "programming", "language"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above are only a few examples of using regular expressions for search and replace operations. They are also used for input validations and data extractions in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// extract number from a string&lt;/span&gt;
&lt;span class="s1"&gt;'I paid $45.99'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;*/&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//["45.99", index: 8]&lt;/span&gt;

&lt;span class="c1"&gt;// validate date in dd-mm-yyyy format&lt;/span&gt;
&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'23-12-89'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;✌️ I write about &lt;strong&gt;modern JavaScript, Node.js, Spring Boot&lt;/strong&gt;, and all things &lt;strong&gt;web development&lt;/strong&gt;. &lt;a href="https://attacomsian.com/newsletter" rel="noopener noreferrer"&gt;&lt;strong&gt;Subscribe to my newsletter&lt;/strong&gt;&lt;/a&gt; to get web development tutorials &amp;amp; protips every week.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Like this article?&lt;/strong&gt; &lt;a href="https://twitter.com/attacomsian" rel="noopener noreferrer"&gt;Follow @attacomsian on Twitter&lt;/a&gt;. You can also follow me on &lt;a href="https://linkedin.com/in/attacomsian" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; and &lt;a href="https://dev.to/attacomsian"&gt;DEV&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
