<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>JavaScript on Coderrob</title><link>https://coderrob.com/tags/javascript/</link><description>Recent content in JavaScript on Coderrob</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Mon, 27 Apr 2026 11:00:00 -0500</lastBuildDate><atom:link href="https://coderrob.com/tags/javascript/index.xml" rel="self" type="application/rss+xml"/><item><title>JavaScript 'this' and Arrow Functions Explained</title><link>https://coderrob.com/posts/javascript-this-and-arrow-functions-explained/</link><pubDate>Mon, 27 Apr 2026 11:00:00 -0500</pubDate><guid>https://coderrob.com/posts/javascript-this-and-arrow-functions-explained/</guid><description>&lt;p&gt;JavaScript functions do not all decide &lt;code&gt;this&lt;/code&gt; the same way.&lt;/p&gt;
&lt;p&gt;Regular functions usually get &lt;code&gt;this&lt;/code&gt; from how they are called. Arrow functions do not create their own &lt;code&gt;this&lt;/code&gt; at all.&lt;/p&gt;
&lt;p&gt;This post is about two questions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Where does a regular function get &lt;code&gt;this&lt;/code&gt; from?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Why does an arrow function behave differently?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;code&gt;this&lt;/code&gt; is one of the easiest JavaScript concepts to misunderstand because it looks like scope.&lt;/p&gt;
&lt;p&gt;It is not scope.&lt;/p&gt;</description></item><item><title>JavaScript Closures and Modified Closures Explained</title><link>https://coderrob.com/posts/javascript-closures-and-modified-closures-explained/</link><pubDate>Mon, 27 Apr 2026 10:00:00 -0500</pubDate><guid>https://coderrob.com/posts/javascript-closures-and-modified-closures-explained/</guid><description>&lt;p&gt;Closures show up any time a JavaScript function uses a variable defined from outside its own curly braces.&lt;/p&gt;
&lt;p&gt;That makes them common in callbacks, event handlers, timers, factory functions, and plenty of code that passes functions around.&lt;/p&gt;
&lt;p&gt;This post is about two questions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What is a closure?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What happens when a closed-over variable is modified before the function uses it?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The short version:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A closure happens when a function keeps access to variables from its surrounding scope, even after that outer scope has finished running.&lt;/p&gt;</description></item><item><title>JavaScript Hoisting Explained</title><link>https://coderrob.com/posts/javascript-hoisting-explained/</link><pubDate>Sun, 26 Apr 2026 10:00:00 -0500</pubDate><guid>https://coderrob.com/posts/javascript-hoisting-explained/</guid><description>&lt;p&gt;Hoisting is JavaScript&amp;rsquo;s setup behavior for declarations.&lt;/p&gt;
&lt;p&gt;It affects whether a function or variable can be used before the line where it appears in the file. That matters because &lt;code&gt;function&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt; do not all behave the same way.&lt;/p&gt;
&lt;p&gt;This post is about two questions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;When does JavaScript create the name?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What value, if any, is available before the declaration line runs?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Hoisting is usually explained as &amp;ldquo;JavaScript moves declarations to the top.&amp;rdquo;&lt;/p&gt;</description></item><item><title>JavaScript Var, Let, and Const Explained</title><link>https://coderrob.com/posts/javascript-var-let-and-const-explained/</link><pubDate>Sat, 25 Apr 2026 10:00:00 -0500</pubDate><guid>https://coderrob.com/posts/javascript-var-let-and-const-explained/</guid><description>&lt;p&gt;Most JavaScript code starts with a simple act: you give a value a name. We call that a variable declaration.&lt;/p&gt;
&lt;p&gt;That sounds small, but the way you create that name affects how the rest of your code can use it. A variable might be available only inside a small &amp;ldquo;if&amp;rdquo; block, across an entire function, or in places you did not really mean to share it.&lt;/p&gt;
&lt;p&gt;That is why &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt; are worth understanding before the code gets complicated.&lt;/p&gt;</description></item><item><title>JavaScript Promise</title><link>https://coderrob.com/posts/javascript-promise/</link><pubDate>Wed, 22 Oct 2025 21:00:00 -0500</pubDate><guid>https://coderrob.com/posts/javascript-promise/</guid><description>&lt;p&gt;A &lt;code&gt;Promise&lt;/code&gt; is a guaranteed placeholder value for what a function or series of functions will return.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s a &lt;em&gt;promise&lt;/em&gt; to return a value eventually.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The function swears this time is different. You can trust it. It swears it&amp;rsquo;ll get it back to you in no time.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If you haven&amp;rsquo;t already, check out my post on &lt;a href="../javascript-callbacks"&gt;JavaScript Callbacks&lt;/a&gt; where we dove into callback hell and why we desperately needed something better. Spoiler: Promises are that something better.&lt;/p&gt;</description></item><item><title>Rollup, UUID, and Error Crypto getRandomValues() Not Supported - Solved</title><link>https://coderrob.com/posts/rollup-and-error-crypto-getrandomvalues-not-supported/</link><pubDate>Sat, 24 Aug 2024 00:32:53 -0500</pubDate><guid>https://coderrob.com/posts/rollup-and-error-crypto-getrandomvalues-not-supported/</guid><description>&lt;p&gt;I ran into this error while using Rollup and the &lt;code&gt;uuid&lt;/code&gt; package:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Error: Crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The problem? It boiled down to this small mistake in my Rollup config:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#000;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-js" data-lang="js"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#0f0"&gt;// rollup.config.js
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;plugins: [
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; nodeResolve({
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; extensions: [&lt;span style="color:#87ceeb"&gt;&amp;#39;.ts&amp;#39;&lt;/span&gt;, &lt;span style="color:#87ceeb"&gt;&amp;#39;.js&amp;#39;&lt;/span&gt;],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; exportConditions: &lt;span style="color:#87ceeb"&gt;&amp;#39;node&amp;#39;&lt;/span&gt;, &lt;span style="color:#0f0"&gt;// Wrong: should be an array
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }),
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#0f0"&gt;// Other plugins...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;],
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The solution was simple. &lt;code&gt;exportConditions&lt;/code&gt; needs an array, not a string:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#000;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-js" data-lang="js"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#0f0"&gt;// rollup.config.js
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;plugins: [
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; nodeResolve({
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; extensions: [&lt;span style="color:#87ceeb"&gt;&amp;#39;.ts&amp;#39;&lt;/span&gt;, &lt;span style="color:#87ceeb"&gt;&amp;#39;.js&amp;#39;&lt;/span&gt;],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; exportConditions: [&lt;span style="color:#87ceeb"&gt;&amp;#39;node&amp;#39;&lt;/span&gt;], &lt;span style="color:#0f0"&gt;// Fixed: now it&amp;#39;s an array
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }),
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#0f0"&gt;// Other plugins...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;],
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;TypeScript would&amp;rsquo;ve caught this, but in plain JS, it slipped through. Lesson (re)learned. Always verify.&lt;/p&gt;</description></item><item><title>JavaScript Spread Syntax Explained</title><link>https://coderrob.com/posts/javascript-spread-syntax-explained/</link><pubDate>Thu, 03 Mar 2022 21:28:27 -0600</pubDate><guid>https://coderrob.com/posts/javascript-spread-syntax-explained/</guid><description>&lt;p&gt;The JavaScript spread &lt;code&gt;...&lt;/code&gt; syntax is amazing.&lt;/p&gt;
&lt;p&gt;What it does is let you take the individual items from an array, or the individual properties from an object, and spread them out into another place.&lt;/p&gt;
&lt;p&gt;That &amp;ldquo;another place&amp;rdquo; might be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a new array&lt;/li&gt;
&lt;li&gt;a new object&lt;/li&gt;
&lt;li&gt;the arguments being passed into a function&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When I first learned to use spread syntax I was a little confused about what it was actually doing. The three little dots looked simple enough, but JavaScript has a long history of making simple-looking things weird.&lt;/p&gt;</description></item><item><title>JavaScript Callbacks</title><link>https://coderrob.com/posts/javascript-callbacks/</link><pubDate>Mon, 03 May 2021 15:00:00 -0500</pubDate><guid>https://coderrob.com/posts/javascript-callbacks/</guid><description>&lt;h2 id="brief-history-of-callbacks"&gt;Brief History of Callbacks&lt;/h2&gt;
&lt;p&gt;It all starts with the callback function.&lt;/p&gt;
&lt;p&gt;A callback function is just a plain JavaScript function that is passed into another function as an argument.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s it. Nothing special.&lt;/p&gt;
&lt;p&gt;This callback function can be used to return data, or to signal that some event took place.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;ve worked with web development you&amp;rsquo;ve definitely crossed paths with callbacks.&lt;/p&gt;
&lt;p&gt;Think of a button &lt;code&gt;click&lt;/code&gt; event for a web page.&lt;/p&gt;</description></item><item><title>JavaScript Function Parameters and Arguments Explained</title><link>https://coderrob.com/posts/javascript-function-parameters-and-arguments-explained/</link><pubDate>Thu, 17 Sep 2020 00:46:15 -0500</pubDate><guid>https://coderrob.com/posts/javascript-function-parameters-and-arguments-explained/</guid><description>&lt;h2 id="javascript-function-signatures"&gt;JavaScript Function Signatures&lt;/h2&gt;
&lt;p&gt;Alright, you&amp;rsquo;ve probably seen functions before. Something like this maybe?&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#000;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-js" data-lang="js"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f00"&gt;function&lt;/span&gt; doSomething(name, desc, task) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#0f0"&gt;// did something
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This function, named &lt;code&gt;doSomething&lt;/code&gt;, takes three &lt;code&gt;parameters&lt;/code&gt; as part of its function signature. These parameters named &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;desc&lt;/code&gt;, and &lt;code&gt;task&lt;/code&gt; are the names of the values being sent into the function.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m going to use a sportsball reference here so be warned. You can think of the function as a net that gets various types of objects tossed into the hoop &lt;code&gt;( )&lt;/code&gt; where it triggers sports points.&lt;/p&gt;</description></item></channel></rss>