<?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 dev.endevour</title><link>https://devendevour.iankulin.com/tags/javascript/</link><description>Recent content in Javascript on dev.endevour</description><generator>Hugo</generator><language>en-AU</language><lastBuildDate>Mon, 14 Apr 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://devendevour.iankulin.com/tags/javascript/index.xml" rel="self" type="application/rss+xml"/><item><title>Functional Javascript array methods</title><link>https://devendevour.iankulin.com/functional-javascript-array-methods/</link><pubDate>Mon, 14 Apr 2025 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/functional-javascript-array-methods/</guid><description>&lt;p&gt;I&amp;rsquo;ve been whipping up a little mock-database unit that has a few access functions but actually stores the data as arrays for a demo project for a post I&amp;rsquo;m writing. In the process I wrote this gem:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;export function dbOrdersAdd(order) {
 const orderCopy = { ...order };
 // since id is a stringified number, finding the max is a bit of a mess
 const maxId = orders.reduce((max, o) =&amp;gt; Math.max(max, parseInt(o.id)), 0);
 orderCopy.id = String(maxId + 1);
 orders.push(orderCopy);
 return { ...orderCopy };
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the comment I&amp;rsquo;m claiming the code is a bit of a mess (and from a readability point that&amp;rsquo;s true) but actually I love the elegance of using the &lt;code&gt;reduce()&lt;/code&gt; method here.&lt;/p&gt;</description></item><item><title>Node.js built in test runner</title><link>https://devendevour.iankulin.com/node-js-built-in-test-runner/</link><pubDate>Mon, 17 Mar 2025 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/node-js-built-in-test-runner/</guid><description>&lt;p&gt;For the longest time, I&amp;rsquo;ve been using &lt;a href="https://mochajs.org/" target="_blank" rel="noopener"&gt;Mocha&lt;/a&gt; (test runner) and &lt;a href="https://www.chaijs.com/" target="_blank" rel="noopener"&gt;Chai&lt;/a&gt; (assertion library) for my JS testing. They are reliable old friends.&lt;/p&gt;
&lt;p&gt;One of the effects of the existence of &lt;a href="https://bun.sh/" target="_blank" rel="noopener"&gt;Bun&lt;/a&gt; and &lt;a href="https://deno.com/" target="_blank" rel="noopener"&gt;Deno&lt;/a&gt; has been to spur Node onto adding some new features, so after appearing as an experimental feature in 18, the Node test runner dropped in Node 20.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m not sure if the familiar unit test layout of Mocha and Node is inherited from Jest, or comes from older testing frameworks of which JUnit and NUnit were the first ones I&amp;rsquo;d ever used. Before that I just used to write tests as lumps of assertions in regular code - which worked but wasn&amp;rsquo;t as pleasant to use as a proper unit test setup. Regardless, the system of bundling a few tests together and having them all run and spit out green ticks is not a new one.&lt;/p&gt;</description></item><item><title>Code reuse by publishing to NPM</title><link>https://devendevour.iankulin.com/code-reuse-by-publishing-to-npm/</link><pubDate>Mon, 14 Oct 2024 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/code-reuse-by-publishing-to-npm/</guid><description>&lt;p&gt;If you find yourself copying over a source file from one Node project to another because it&amp;rsquo;s a handy utility you wrote and are used to using, you&amp;rsquo;re only doing it half right. A better way to do this is to publish your utility to the &lt;a href="https://www.npmjs.com" target="_blank" rel="noopener"&gt;Node Package Manager&lt;/a&gt; (NPM). That way you can just import your utility where ever you need it, it will live in the &lt;code&gt;node_modules&lt;/code&gt; of any project that uses it, and most importantly, updates are sorted out automatically - because that&amp;rsquo;s what package managers are good at.&lt;/p&gt;</description></item><item><title>Authentication basics for Node apps</title><link>https://devendevour.iankulin.com/authentication-basics-for-node-apps/</link><pubDate>Mon, 19 Aug 2024 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/authentication-basics-for-node-apps/</guid><description>&lt;p&gt;&lt;a href="https://unsplash.com/photos/calahorra-tower-torre-de-la-calahorra-in-cordoba-spain-a-fortified-gate-built-during-the-late-12th-century-by-the-almohads-to-protect-the-nearby-roman-bridge-in-the-historic-center-of-cordoba-andalusia-spain-ECsukeqrDoo" target="_blank" rel="noopener"&gt;&lt;img src="https://devendevour.iankulin.com/images/screen-shot-2024-08-10-at-8.59.01-pm.jpg" alt="" class="img-responsive"&gt; &lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Pretty much every serious web app needs to include a way for users to log in securely and to be served their content. Since there&amp;rsquo;s a lot of complexity in this, it&amp;rsquo;s highly advisable to use good libraries to support this. In a future post we&amp;rsquo;re going to use those libraries, but first I want to explain what&amp;rsquo;s happening at the lower level and tease out some of the concepts as we build a secure system from the ground up.&lt;/p&gt;</description></item><item><title>User Sessions &amp;amp; Cookies in Node</title><link>https://devendevour.iankulin.com/user-sessions-cookies-in-node/</link><pubDate>Fri, 09 Feb 2024 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/user-sessions-cookies-in-node/</guid><description>&lt;p&gt;When you are learning app development, you can create all sorts of apps that work for you, but for any serious app, it&amp;rsquo;s going to need to authenticate users and persist sessions across visits. So much so, that as a professional developer, you&amp;rsquo;ll probably build that out first - it becomes a sort of boiler plate you always drop in.&lt;/p&gt;
&lt;p&gt;In this post, focusing on the server side, using node, express, and particularly express-session, I&amp;rsquo;ll try and build up from nothing to a reasonable usable user login system explaining the increasing complexity and reasons for it. To follow along you&amp;rsquo;ll need basic familiarity with node and express.&lt;/p&gt;</description></item><item><title>React Expense Tracker App</title><link>https://devendevour.iankulin.com/react-expense-tracker-app/</link><pubDate>Mon, 22 Jan 2024 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/react-expense-tracker-app/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/moneycoachjen_76363_woman_representing_money_2f84bb41-99db-4cb8-bc07-78e759e8b1f9.jpg" alt="" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m focused on React frontend skills these holidays, and &lt;a href="https://codewithmosh.com/p/ultimate-react-part1" target="_blank" rel="noopener"&gt;working through Mosh&amp;rsquo;s React 18&lt;/a&gt; course. The exercise today (which I think I nailed, although I spent more than the recommended hour on) was a small app to track expenses. Like most of Mosh&amp;rsquo;s exercises it was great because it exercised all the understandings up to that point - so it&amp;rsquo;s a good starting React project. It used Zod for the form validation which is completely new to me, but looks great.&lt;/p&gt;</description></item><item><title>Copying Objects in JS</title><link>https://devendevour.iankulin.com/copying-objects-in-js/</link><pubDate>Mon, 15 Jan 2024 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/copying-objects-in-js/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/nullgrim_three_ominous_mechanical_cyber_demon_sisters_asajj_ven_1eaa87e3-99a8-4c4a-9bc0-ec8fb807caad.jpg" alt="" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve paid for a month of Mosh to do his &lt;a href="https://codewithmosh.com/p/ultimate-react-part1" target="_blank" rel="noopener"&gt;React 18 course&lt;/a&gt; , and one of the things he makes a big deal about is not to go too deep with nested objects for your state. As soon as you start to update them it becomes apparent why.&lt;/p&gt;
&lt;p&gt;Because of the way state works in React, if we need to update part of an object it has to be deep copied, the changes applied to this copy, then that new copy passed back to React to replace the previous version. So, how we copy objects becomes a matter of particular interest.&lt;/p&gt;</description></item><item><title>htmx - A To Do Example</title><link>https://devendevour.iankulin.com/htmx-a-to-do-example/</link><pubDate>Fri, 05 Jan 2024 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/htmx-a-to-do-example/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/0-eawgkaegdkhvqwcg.png" alt="" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;HTMX is an interesting project to me, and I&amp;rsquo;ve used it a bit in my large collection of 70% completed side projects, but haven&amp;rsquo;t really discussed it here. The plan for this post is to talk briefly about what it is exactly, then convert a simple &amp;lsquo;conventional&amp;rsquo; (HTML/CSS/Javascript) app to htmx and think about some the differences.&lt;/p&gt;
&lt;h3 id="htmx"&gt;htmx&lt;/h3&gt; &lt;p&gt;You could (I recommend you do) read the &lt;a href="https://hypermedia.systems/book/contents/" target="_blank" rel="noopener"&gt;book&lt;/a&gt; about the concepts behind &lt;a href="https://htmx.org/" target="_blank" rel="noopener"&gt;htmx&lt;/a&gt; . Carson Gross (the man behind htmx) calls it a book, but its quite the treatise, it could fairly be called a manifesto.&lt;/p&gt;</description></item><item><title>Displaying markdown as HTML</title><link>https://devendevour.iankulin.com/displaying-markdown-as-html/</link><pubDate>Wed, 08 Nov 2023 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/displaying-markdown-as-html/</guid><description>&lt;p&gt;In the spirit of over-complicating things, when I wanted to collect all the links to the services on my homelab into one place, I decided I needed to write them in markdown, and have them converted on the fly into HTML by a server. Then when I couldn&amp;rsquo;t find exactly what I was after (&lt;a href="http://harpjs.com/" target="_blank" rel="noopener"&gt;Harp&lt;/a&gt; was closest) of course, I decided to write it.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/distracted.jpg" alt="" class="img-responsive"&gt; &lt;/p&gt;
&lt;h3 id="markdown"&gt;Markdown&lt;/h3&gt; &lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="noopener"&gt;Markdown&lt;/a&gt; has definitely been having it&amp;rsquo;s moment over the last couple of years. It&amp;rsquo;s a simple open format mark-up language that is quite readable in it&amp;rsquo;s source form. Although it&amp;rsquo;s now very fashionable as an input for static site generators, most people will have run in to it when adding simple formatting to forum comments or on instant messaging platforms.&lt;/p&gt;</description></item><item><title>Using Node.js to return a static file</title><link>https://devendevour.iankulin.com/using-node-js-to-return-a-static-file/</link><pubDate>Sun, 02 Jul 2023 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/using-node-js-to-return-a-static-file/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/rajeshtva_node.js_609056a9-3b73-46f5-bc4f-c1f110e3a367.png" alt="" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;As mentioned in the &lt;a href="https://devendevour.iankulin.com/complicating-the-temperature-api/"&gt;previous post&lt;/a&gt; , stage one is just to return the same static text file, but from the Node server, rather than NGINX. That&amp;rsquo;s non-trivial to a rank beginner since I need to figure out 1) how to serve a static file from Node, and 2) how to configure NGINX to hand off calls to the API to Node. This post will look at both of those, but it&amp;rsquo;s first probably worth just setting out what each of the puzzle pieces are.&lt;/p&gt;</description></item><item><title>Types of Concern</title><link>https://devendevour.iankulin.com/types-of-concern/</link><pubDate>Fri, 13 Jan 2023 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/types-of-concern/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/pucker_medieval_manuscript_drawing_of_a_peasant_holding_a_macbo_534a8a13-44b2-44cc-8916-5e246609e39d.jpg" alt="medieval manuscript drawing of a peasant holding a MacBook - midjourney" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;I am still struggling with the dynamic typing of JS. I guess the benefit of such an approach is needing less characters - which makes sense in a scripting language like bash, but in real programming it opens us up to a whole class of avoidable errors.&lt;/p&gt;
&lt;p&gt;To program defensively in JS would mean loading the start of function with a series of type checks. I don&amp;rsquo;t see much of that in other people&amp;rsquo;s code, so I assume we just, don&amp;rsquo;t?&lt;/p&gt;</description></item><item><title>Lost in Translation</title><link>https://devendevour.iankulin.com/lost-in-translation/</link><pubDate>Wed, 11 Jan 2023 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/lost-in-translation/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/pucker_two_female_robots_having_a_confusing_conversation_2d32f035-3a1e-4e9f-a335-f7c395190925.jpg" alt="" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;We&amp;rsquo;re in a pretty good place now (compared to a few years ago) in terms of being able to rely on JavaScript behaving the same on different platforms. There&amp;rsquo;s still some differences (mostly in when things are implemented) but overall, not to bad once you decide to no longer support Internet Explorer.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/JavaScript" target="_blank" rel="noopener"&gt;In times past, it was a lot more painful&lt;/a&gt; . A few of approaches to deal with this arose. One is to let a library, such as &lt;a href="https://jquery.com/" target="_blank" rel="noopener"&gt;jQuery&lt;/a&gt; or a &lt;a href="https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills" target="_blank" rel="noopener"&gt;polyfill&lt;/a&gt; deal with it, and the other is use a translation utility such as Babel to down convert (transpile) your modern JavaScript to something that will run in more browsers.&lt;/p&gt;</description></item><item><title>Functions in JavaScript</title><link>https://devendevour.iankulin.com/functions-in-javascript/</link><pubDate>Mon, 09 Jan 2023 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/functions-in-javascript/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/pucker_factory_with_robot_workers_on_an_assembly_line_making_bo_dadc6d24-8873-48f2-97aa-df5508e6e625-1.jpg" alt="" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;As with other languages, functions are a little lumps of code with their own scope. They can optionally take some arguments, and optionally return a value.&lt;/p&gt;
&lt;p&gt;In JavaScript they often have names, can be passed around as types and have a condensed form suitable for functional programming.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;function addNums(a, b) {
 return a+b;
}

console.log(addNums(3,4)) // 7
&lt;/code&gt;&lt;/pre&gt;&lt;h4 id="scope"&gt;Scope&lt;/h4&gt; &lt;p&gt;Arguments are passed in by value so they have local scope only in the function body.&lt;/p&gt;</description></item><item><title>Things I love about Swift after a week of JavaScript</title><link>https://devendevour.iankulin.com/things-i-love-about-swift-after-a-week-of-javascript/</link><pubDate>Fri, 06 Jan 2023 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/things-i-love-about-swift-after-a-week-of-javascript/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/swift-logo-punching-the-javascript-logo.jpg" alt="Swift logo punching the JavaScript logo - Stable Diffusion" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;So, a week into JavaScript, what am I missing? The techie in me wants to say things like Automatic Reference Counting, but actually, at my junior level, I don&amp;rsquo;t run into memory management issues on the day-to-day, so what really do I miss?&lt;/p&gt;
&lt;h4 id="determinism"&gt;Determinism&lt;/h4&gt; &lt;p&gt;When I build an iOS app, it&amp;rsquo;s frozen in time. The functions inside are always going to stay the same. There might be a future version of iOS that won&amp;rsquo;t run it, but as long as it runs, any pure functions inside it will return the same value. The process of compiling it locks that in. Likewise, any libraries that are complied with it.&lt;/p&gt;</description></item><item><title>Step Ahead</title><link>https://devendevour.iankulin.com/one-step/</link><pubDate>Wed, 04 Jan 2023 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/one-step/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/pucker_giant_girl_leaping_for_joy_in_the_forest_childrens_book__eadb2294-124d-46e0-a0ca-f94a1a9305ea.jpg" alt="giant girl leaping for joy in the forest children&amp;rsquo;s book - midjourney" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;I was a bit pleased with myself when I started the next content element in the Complete Web Developer course to find that one and a half of the extensions I&amp;rsquo;d made to the tutorial app for my own fun were specified as the next task.&lt;/p&gt;
&lt;p&gt;In my previous post, I&amp;rsquo;d talked about using a class to denote if an item was completed, and using a style to indicate this by crossing it out. What I haven&amp;rsquo;t discussed was that I&amp;rsquo;d captured right click events on the list items to make this delete them. I wasn&amp;rsquo;t entirely happy with that for a couple of reasons:&lt;/p&gt;</description></item><item><title>Are you okay JavaScript arrays?</title><link>https://devendevour.iankulin.com/are-you-okay-javascript-arrays/</link><pubDate>Sat, 31 Dec 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/are-you-okay-javascript-arrays/</guid><description>&lt;p&gt;As a visitor from sensible type-safe land, this makes me uncomfortable:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/screen-shot-2022-12-23-at-8.52.06-am.jpg" alt="" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;As I keep learning, I&amp;rsquo;m interested to find out if JavaScript objects turn out to just be arrays. To get from here to there, you&amp;rsquo;d just need to be able to use some sort of self[2] notation to access properties from inside the functions.&lt;/p&gt;</description></item><item><title>Running Javascript in VS Code</title><link>https://devendevour.iankulin.com/running-javascript-in-vs-code/</link><pubDate>Tue, 27 Dec 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/running-javascript-in-vs-code/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/screen-shot-2022-12-21-at-11.08.17-am.png" alt="" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve been using the &lt;a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer" target="_blank" rel="noopener"&gt;Live Server&lt;/a&gt; plugin to see HTML &amp;amp; CSS updated as I edit, and that will also be useful when I start using Javascript for web development, but as you can see above, I&amp;rsquo;m not quite up to that. It seemed there should be a way to run JS in VS Code, and it turns out it&amp;rsquo;s easy.&lt;/p&gt;
&lt;p&gt;You just need something installed that can run Javascript. Node.js is the obvious choice, and you&amp;rsquo;re going to need it later in your development journey. Just i&lt;a href="https://nodejs.org/en/download/" target="_blank" rel="noopener"&gt;nstall Node.js&lt;/a&gt; then the first time you try to run some JS in VS code, it will ask you what to use, select Node and you&amp;rsquo;re in business.&lt;/p&gt;</description></item></channel></rss>