JavaScript Articles

Submit a Static Website Form with Cloudflare Workers

Build a form on a static website. Use Cloudflare Workers to send an email on form submission, with Sentry to log errors & Google Captcha to prevent spam. All these can be used for free.

Set asp-append-version True by Default for JavaScript, & CSS to the Bust Cache

When I add a JavaScript file or CSS file in .NET, I want asp-append-version set to true 99.9% of the time. This way I don't have to tell users or testers to clear their cache. Here's an easy way to set the default to true to avoid writing it each time.

How to Get a CSS Variable with JavaScript and Set One Too

While working on a redesign, I needed a way for JavaScript to get the value of a CSS variable to determine the state of a page. Lucky for us, there is a browser compatible and easy method.

Use Sass Variables In Typescript & Javascript

Having one true source of data is one of the first golden rules in software development. When creating components in JavaScript, you may want to add styles and classes that are also in your scss files. In an ideal world, you want to be able to make changes to these styles in one place and let your code update the rest.

How to use Default Props in React with TypeScript

Adding default props in React with TypeScript has been a pain. TypeScript 3 is making this process simple.

Use a TypeScript Definition Without Importing

There may come a time where you want to reference types in your TypeScript file without importing the code. This is common if you have a script tag somewhere else that is importing JavaScript from a public CDN of a popular library.

Why is TypeScript Adding Class Comments to my Code

I noticed all my TypeScript compiled files had been modified after a recent change. I hadn't changed anything in them so this gave me some concern. What I found was TypeScript added a /** @class */ comment to the modified files.

Adding Optional Parameters to a Javascript Function

Here's a great pattern for adding optional values to a function in JavaScript.

The Power of Destructuring in JavaScript

In my free time, I've been messing around with a functional programming language built for the Erlang VM called Elixir. One of my favorite features of Elixir is pattern matching. As of ES6, we now have some pattern matching features in JavaScript. One of those is destructuring. Using destructuring will simplify your code & make it more readable.

TypeScript Cannot Invoke an Expression whose Type Lacks a Call Signature

I have a love|hate relationship with TypeScript. I love it when it works & hate it when it doesn't do what I think it should. I was trying to clean up some code and wrote the following

Using Ternary Operators in ES6 String Templates

The new ES6 version of JavaScript introduced Template Strings which allow for improved readability of code when working with multiple line strings.
Let's Connect