Professional Development · Technology

Getting Your Head Around JavaScript Closures

One concept that is considered “advanced” in JavaScript is closures. MDN defines closures as: A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time… Continue reading Getting Your Head Around JavaScript Closures

Professional Development · Technology

MERN Authorization with Passport.js

Any web application of significant complexity is going to require user-level security. In this post, I walk through how to create authorization for users in a MERN (MongoDB, Express, React, and Node) stack web application. Full code is available here: https://github.com/dikuw/mern-passport This post assumes knowledge of React and node.js and just shows how to incorporate… Continue reading MERN Authorization with Passport.js

Professional Development

Refactoring a While Loop with Recursion in JavaScript

A quick example of how to refactor out a While loop in JavaScript by using recursion instead. The problem is as follows (from TestDome): Your company assigns each customer a membership ID, and you are implementing a check digit for those IDs. The check digit should be calculated by adding up all digits in each… Continue reading Refactoring a While Loop with Recursion in JavaScript

Professional Development

Class properties versus Constructor in React

A simple counter component in React can look like this: The component initializes the state variable “counter” with the value zero and then updates it by one every time the button is clicked. See it working here. This same code can be written much more cleanly using class properties instead of constructor properties, like so:… Continue reading Class properties versus Constructor in React

Knowledge · Professional Development

Clean Aggregation with JavaScript ‘Reduce’

A common beginner (?) programming question is as follows: Given an array of items, find how many instances of each item occurs in the array. For example, given the below array of US states, return an object with the count of number of instances of each state: The interesting thing about this problem is it… Continue reading Clean Aggregation with JavaScript ‘Reduce’

Entrepreneurship

Regulatory Considerations for Consumer Electronics Products

Designing a new consumer electronic product from scratch has led me to the broad and intimidating subject of regulatory requirements. If you want to import original products from China, or Vietnam, or India, or anywhere else, to the US, Europe, Australia, or other western markets, you are required by law to comply with numerous regulations… Continue reading Regulatory Considerations for Consumer Electronics Products