DEV Community

loading...
Alex Lohr profile picture

Alex Lohr

...former musician, voice actor, martial artist, turned senior front-end developer.

Location Germany Joined Joined on  Twitter logo
Work

Senior Software Engineer at LogMeIn Inc.

Last 250 comments

It's alright to take a break

After realizing what had happened, I first took a break of on...

It's alright to take a break

With 2 kids and the pandemic, I had to reduce my work time to...

Explain "Code Smells" like I'm five

"Code smell" is a term to thrash-talk code without bringing u...

Epicodus 1/20/21 jQuery and Javascript

You can avoid to use ready if you bind your handlers directly...

How to Compare Decimals in JavaScript

The problem here is that all numbers in JS are IEEE 754 64 bi...

Why do many Javascript libraries or documentations keep using callback, var, == or function keywords?

callback: a many libraries aim to be isomorphic, i.e. work b...

Refactoring old code

Maybe use the spread operator instead: const newOutput = O...

Which Linux distro is most stable for daily use?

My last switch brought me to void linux and it is rock solid ...

Regex..why can’t you just be normal? 🀯

Regex is a simple yet powerful concept, comparable to a hand ...

Testing element dimensions without the browser

I had expected something more dramatic, e.g. a way to add a C...

Considering `??` vs `||`

I wouldn't go so far to call them sins, but I agree that you ...

Deep merge Objects in Javascript with Mergerino

This use case is always a bit difficult when it comes to arra...

Using the shy soft hyphen in HTML

There's another interesting standard here: developer.mozilla....

How consistently does your organization update dependencies?

We have a renovate bot to do that for us... unless something ...

Null Conditional Operator for fallback images

In this case, it would be sensible to replace the nullish coa...

How does troll (tech) become cute?

TrollTech was originally located in norway, a scandinavian co...

A Detailed Breakdown of HTML Form Event Attributes

You cannot have multiple events then. If you set the DOM leve...

Typeof array is an object in javascript

Class instances are also objects. An array literal is just an...

A Detailed Breakdown of HTML Form Event Attributes

You shouldn't use the DOM level 1 event attributes (on...) an...

Do You Actually Know What A String In JavaScript Is? Here's What I Found.

You cannot change a string in JS, just instantiate a new one ...

JavaScript match values in two arrays

Instead of array1.indexOf(obj) !== -1, you can use array1.inc...

JavaScript removing HTML tags

Back in the old jQuery days, there was a long discussion if p...

JavaScript reduce() method

I don't really get that "underwater" question. It is only ite...

JavaScript reduce() method

Array.prototype.reduce((state, item) => newState, initial...

What do you love most about coding?

There's always something new to learn You can create somethi...

Vanilla JavaScript detecting the operating system

This seems like a prime example for the use of regexp: /\b...

CSS equal height columns

There's an even more old-school trick with display: table/tab...

Be aware when cloning objects in JavaScript! πŸ‘―β€β™€οΈ

Here's the initial draft: github.com/atk/object-clone-proposa...

Be aware when cloning objects in JavaScript! πŸ‘―β€β™€οΈ

I guess I'll make a proposal myself, if nobody beats me to it...

Be aware when cloning objects in JavaScript! πŸ‘―β€β™€οΈ

I guess libraries like lodash made it convenient enough to ha...

Be aware when cloning objects in JavaScript! πŸ‘―β€β™€οΈ

Yes and no. JSON.parse/stringify will serialize and deseriali...

Be aware when cloning objects in JavaScript! πŸ‘―β€β™€οΈ

If you want to do it yourself for simple cases, you can just ...

Vanilla JavaScript random colours

You'll still have a chance to hit a number low enough not to ...

Vanilla JavaScript data attribute filters

And it was a nice example. I just find that a lot of front en...

Vanilla JavaScript data attribute filters

Or you let CSS do the job and just create a style tag with th...

Reduce() Method in Javascript

Please do. You're welcome.

Reduce() Method in Javascript

Using modern syntax (arrow function, object decomposition) ma...

What is required or should be done, according to PDPA / GDPR?

Actually, the question is: what mustn't be done. You may not ...

Symbols Are Your Friend Part I: A Gentle Introduction (JS Bits)

console.log is just parsing the output of the .toString() met...

What's the deal with indentation sensitivity hate?

IMO, indentation is not information, but redundancy to increa...

8 important things I learned as a software developer over a decade.

Maybe I should have rephrased that. The sign was meant to be ...

8 important things I learned as a software developer over a decade.

This overlaps rather precisely with my own experience, which ...

Javascript ||, aka Why Doesn't This Work?!

There are two finer points of the language that may be confus...

What do you use to record the screen?

OBS or GotoMeeting (web version - this obviously applies if i...

Taming SVGs with React and TypeScript for enhanced granular control

One pattern you should probably consider: whenever you need m...

Stop Using React

If what you want is more application than web site, go ahead ...

Managing my node versions

For some people, volta may be another interesting choice. It'...

Is there Webview that downloads Chromium if required, and install globally?

But they are installed on virtually every operating system in...

Is there Webview that downloads Chromium if required, and install globally?

There's already such a thing for rust called alcro and for go...

What's the best way to do encapsulation?

It is possible to have the equivalent of private fields insid...

Make Pixel art 10x faster βœ¨πŸ’«

Maybe using a template literal instead of an array will impro...

React Conditional Rendering Best Practices with 7 Different Methods

Small nitpick about your example: const ALERT_STATUS = (mes...

How do you ensure consistent formatting in MS Word?

Even with programmatic styles, just changing the printer will...

What irritates you the most as a developer? πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

First of all, I don't really hate you or your answer, but I'd...

JS / TS?

TypeScript is just JavaScript with some extensions from upcom...

Dates are hard folks

Leap years and time shifts everywhere! They're out to get you...

Automated Pull Requests, to merge or not?

I think the way to go is first build a testing pipeline that ...

Benefits of SVG

One thing that's missing in this list is accessibility: any S...

A Quick Dive Into ES6

I think you didn't do the Iterators/Iterables/Generators just...

How long does it typically take to be productive in a new job?

When I started, I made my first contribution to production wi...

Daily Challenge #259 - Duplicate Encoder

I just love how Rust has a helpful method for about everythin...

Daily Challenge #260 - Subtract the Sum

Rust solution: const FRUITS: [&'static str; 100] = [ ...

Daily Challenge #259 - Duplicate Encoder

Why not use std::str::matches to iterate over the same chars?

Daily Challenge #259 - Duplicate Encoder

Rust πŸ¦€πŸ¦€πŸ¦€πŸ¦€solution:πŸ¦€πŸ¦€πŸ¦€πŸ¦€πŸ¦€ πŸ¦€ fn encode_duplicate_characters(te...

I created a website, but when do I have to notify users that I want your cookies?

Ah, I confused that. It was the BGH that confirmed the EuGH s...

I created a website, but when do I have to notify users that I want your cookies?

Local storage never leaves the user's client by itself, so un...

I created a website, but when do I have to notify users that I want your cookies?

First, if you don't use cookies, you don't need to notify use...

How much coffee do you drink?

5-6 cups of freshly ground espresso.

Is open-sourcing server-side code a security threat?

You're not fooling anyone if the data structure and the outpu...

Is open-sourcing server-side code a security threat?

In most cases, the API itself will not be worth too much with...

Is open-sourcing server-side code a security threat?

The first line of defense is your developers. You should pay ...

Is open-sourcing server-side code a security threat?

First, bad people will find vulnerabilities with or without y...

Is open-sourcing server-side code a security threat?

Not disclosing your source code is mere security by obscurity...

VSCode vs Vim

As someone who uses both, I don't see why there must be a "vs...

What is your pettiest programming-related opinion?

My biggest pet peeve is when people say that X was superior t...

πŸ‘¨πŸ»β€πŸ’» UnderStand the Most Powerful πŸ’ͺ Function of Javascript

I believe there's a more powerful function in JS, which is St...

The Lies of "===" operator

Actually, both are valid cases, since === compares the actual...

Have you ever had to take an ethical stand while on the job as a developer?

I was tasked to write a fingerprinting engine for advertiseme...

Why is Lodash Still Useful?

A very nice example is _.isEmpty(): in most cases, you are ...

Why is Lodash Still Useful?

To do the same with ES methods, just the first two examples...

Random colour with JavaScript

You could also use (16777216 * (1 + Math.random()) | 0).toS...

Algorithm 101: 3 Ways to Create Pig Latin

Here's what I would have come up with: const splitWord = ...

Refactoring: My 6 favorite patterns

Exactly. Code is meant to be read by developers. Computers ...

Refactoring: My 6 favorite patterns

For #4, TypeScript has enums, which are a lightweight and l...

`useWindowSize` React Hook To Handle Responsiveness In JavaScript

I would prefer making this more general by taking a configu...

The Magic Behind JavaScript Syntax Shortcuts

Welcome to the world of code golfing: github.com/jed/140byt...

The Magic Behind JavaScript Syntax Shortcuts

Welcome to the world of code golfing: github.com/jed/140byt...

Your code should tell a story: Tips for writing code for others to read

If you can, use TypeScript to document the API. The reading...

Run useEffect Only Once :React

Also if you only want to run it on unmount, you can use us...

YEStifications: Exploring how users engage with notification prompts in the Chrome UX Report

A lot of pages and apps do that, so that would make another...

YEStifications: Exploring how users engage with notification prompts in the Chrome UX Report

I think there are 2 things to consider that make a great di...

What will programming look like in 100 years?

Let me just ask one question: who develops the AI that take...

What will programming look like in 100 years?

I think this prediction is the software development equival...

Stop telling people what are the "best" programming languages to learn

Or just do not write "best programming language" articles a...

Optional booleans?

Because it might only be for one of the use cases of your A...

Optional booleans?

Consider this more modern TS example: const whatever = ({...

Optional booleans?

But if you say booleans cannot be optional, then the conseq...

Optional booleans?

Sorry, but then you just get a lot of enums enum Whatever...

Will client-heavy avatar-based teleconferencing be a thing soon?

High quality video encoding and transmission is definitely ...

Scare me with your one liner

2816..toString(16) Watch out, a JS ghost...

Use Your Voice Effectively for Impactful Presentations

People often concentrate so much on the content of their pr...

3 tips for clean & efficient code

Another thing to consider is the testability of your functi...

On the Occasional Misdiagnosis of "Not Invented Here Syndrome"

Only last week, one of our talented junior developers tried...

Security for the front-end developer

Since you will always need to secure your back end, many fr...

Pass parameter to setTimeout inside a loop - JavaScript closure inside a loop

I only added it for the sake of completeness. While I real...

Pass parameter to setTimeout inside a loop - JavaScript closure inside a loop

Solution 4: use the closure from the setTimeout callback: ...

New browser on the block!

Fingers crossed. Having another competitor will keep the ot...

Should I start by learning vanilla Javascript or a framework?

My standard answer to that question is similar: Get the ba...

How often do you clean your screen/keyboard?

3-4 times a year, I wash my keyboard (it's the Logitech K31...

What would the programming language sorting hat pick for you, and why?

Nowadays, I write mostly TypeScript and love every moment o...

Ads In Your Linters

Simple solution for open source creators who need ad revenu...

Could you review my design, please?

Much better. Go easy on the rounded corners, those look a b...

Could you review my design, please?

Ah, wrong URL, my bad. In this case, much better, but now i...

Could you review my design, please?

which description and name look misplaced? The one at th...

Could you review my design, please?

First of all, you should probably use a monospace font for ...

Welcome to the Big Thread Club, Emma Wedekind. You are the latest winner of the Big Thread Badge. πŸŽ‰

Congratulations, @emmawedekind .

JS Code Golfing - How To Ruin Everyone's Day

Reminds me of Jed's 140byt.es, now discontinued. My first g...

Anagrams Checker - Three JavaScript Solutions

I initially thought about that approach, but discarded it f...

Anagrams Checker - Three JavaScript Solutions

My first solution (ES2019) looks like this: const isAnagr...

You're not worth hiring unless...

Hiring managers are notoriously uninformed about the tech sta...

What does your team do when your communication channels go down?

When slack goes down after our daily, we already know what ...

5 Commandments for TypeScript programmers

a union of string literal types is good enough You'll th...

5 Commandments for TypeScript programmers

I think it is ok to lie a bit in unit tests as long as the ...

Which types of loops are most popular in the programming languages you use?

Lambda loops (Array methods) are now the well-deserved defa...

How is the tech industry contributing to global warming and what can we do to reduce the impact?

Each bit saved is ~2.5fWh less electricity spent ;-)

Why don't fish like React?

...line and sinker :)

What jobs did you hold before you got into software?

I was musician, voice actor, martial arts trainer and furni...

Convince me that types are awesome

For some time, I saw types as a crutch for people who could...

What do you think about the idea that "there should be only one way of doing a thing" in programming languages?

While there have been many attempts in different programmin...

Should a button communicate the current state, the intended behavior, or both?

What we have here is a blend of different paradigms: button...

What's your favorite addition to ES2015+

.then(...) still takes a callback. So while it reads much m...

What's your favorite addition to ES2015+

Let's say, you need to sequentially resolve three promises....

What's your favorite addition to ES2015+

Async/await is so great. No more callback hell ever again.

Tell me a bug story

I once wrote a limited JS parser to remove comments and sti...

How many software developers does it take to screw in a lightbulb?

If you take German developers, it's one and no punchline, b...

What's the most excited you've ever been about a new technology?

Sleep, little one, type systems can be fun! You'll catch th...

What are your non-tech hobbies

I ride my bicycle and do most of the maintenance myself. I ...

What's your commute like?

I love my 10 miles bike commute and ride in any weather. It...

A New Coding Style for Switch Statements in JavaScript/TypeScript

Thanks for taking your valuable time to raise and discuss t...

A New Coding Style for Switch Statements in JavaScript/TypeScript

1) Actually, that things are either handled the same or dif...

A New Coding Style for Switch Statements in JavaScript/TypeScript

I would actually write it like this: switch (body.type) ...

Honey, I Type Checked The Children

A fun way to look at PropTypes :) Nicely written. I see Pr...

7 Javascript Methods That Aid DOM Manipulation

The point here is that you probably shouldn't rely on globa...

7 Javascript Methods That Aid DOM Manipulation

Yes, but only as long as no script overwrites the global re...

7 Javascript Methods That Aid DOM Manipulation

Because it is a security problem, very much like .innerHTML...

7 Javascript Methods That Aid DOM Manipulation

Nice summary. I'm only missing .insertBefore(newChild, refe...

The secret that the fonts industry doesn't want you to know

While with opacity, you can only ever mix the color, with c...

The secret that the fonts industry doesn't want you to know

More than that, you can also use SVG color filters to deriv...

Curing the Superhero syndrome in software engineering

I think here's an underlying issue of the "Superhero", in t...

I’m sorry, but this β€œFull Stack” meme makes me really mad/sad

Actually, having started as full stack (including hardware,...

Pain points In Legacy code refactoring?

1) Lack of readability, inconsistent code 2) Missing tests ...

Being A Woman On The Internet Is... "Fun": A Scientific Study

Unfortunately, we won't ever know the number of men simply ...

JavaScript One-Liners That Make Me Excited

There are a lot of byte saving tips one can employ in code ...

JavaScript One-Liners That Make Me Excited

that can be even more minified: score => (["", "#98FB...

JavaScript One-Liners That Make Me Excited

I can probably do it in even less characters... let me try:...

JavaScript One-Liners That Make Me Excited

Thanks. Not sure if it's faster, but that's usually a non-i...

JavaScript One-Liners That Make Me Excited

You can shave off one more char for your hex color code gen...

What are your favorite programming language syntax features?

Of those, async/await is certainly my favourite. It makes a...

Nevertheless, Ali Coded

Stay strong. It's a shame you have to, though.

VSCode in browser

We need to go deeper. Let the container run in a browser, t...

Creating A Custom, Accessible Drop Down

One more thing I forgot to mention. You should also ensure ...

Creating A Custom, Accessible Drop Down

A small addition: it could also help to select the correct WA...

Regex Cheat Sheet

Just don't forget about those edge cases ;-)

2 Ways to Merge Arrays in JavaScript

To emulate spread parameters in older Javascript, you can u...

How a Type System Improves your JavaScript Code

I still like writing plain old Javascript like we did in th...

Performance measurement of JavaScript solutions to common algorithmic questions (part 1)

It would be best to preallocate the memory, since we know ...

Regex Cheat Sheet

Using the | operator is a dangerous habit. You easily forge...

The Rules of Debugging

I'd like to read more of those bug classifications, especia...

How To Test JavaScript Code In A Browser

Selenium is more a heavy-weight solution for end to end tes...

How To Test JavaScript Code In A Browser

Cypress currently only supports Chromium and electron. Test...

How many ways iterate the objects and arrays in javascript?

Your misunderstanding might be resolved if you take the fol...

How many ways iterate the objects and arrays in javascript?

I knew I forgot something :-) In any case, you won't be fi...

JavaScript typed arrays: Unexpected overflow

Just because a language is specified different to C/C++ doe...

What is a type of "overconfidence" you have observed in developers?

The worst example of this was an applicant for a senior dev...

Compress image in browser? Easy!

That is exactly what I was referring to: you set the qualit...

Compress image in browser? Easy!

Actually, it is a percentage of signal quality for the quan...

JavaScript typed arrays: Unexpected overflow

This is not as much of a quirk as it seems. ++ is supposed ...

Compress image in browser? Easy!

It's more resize than compress. If you wanted compression, ...

There's no such thing as a full stack developer

I started my career full stack (even including hardware suppo...

How many ways iterate the objects and arrays in javascript?

I didn't explain much, just wrote down the first few I coul...

How many ways iterate the objects and arrays in javascript?

// 1 array.forEach(() => { ... }); // 2 array.map(() =&g...

Captain Marvel's Official Website is Amazing

Since the movie is set in the 90s, they used a web design f...

Understanding Web Real-Time Communication

It should be noted that the API and its browser support onl...

Clean up your code with these tips!

What is difficult to read it what is obvious to you strongl...

Clean up your code with these tips!

It's not supported in current ECMAscript. However, a standa...

Clean up your code with these tips!

You're welcome. I'm usually rather eager to solve things wi...

Clean up your code with these tips!

Three minor additions: you can omit the ternary in your cas...

CSS and JS Are at War, Here’s How to Stop It

What is it with some developers that they value their opini...

RxJS Transducer - Harness the Power of RxJS Operators

Arguably, take is present in the form of slice, while the l...

Improving Javascript functional programming with Polyethylene

I think they first aimed to optimize the single methods ins...

Improving Javascript functional programming with Polyethylene

Cool project, though I would argue that you could also impr...

"I need to change this code, but it has no test"

It actually seems to work.

"I need to change this code, but it has no test"

Not sure. Let me test later, have a bunch of meetings ahead...

"I need to change this code, but it has no test"

You can actually write the snapshot itself as if it was cod...

"I need to change this code, but it has no test"

I would disagree on the assertion that snapshots had few va...

Async operations in JavaScript

Still, to the day the main thread runs completely synchrono...

Async operations in JavaScript

We should clarify which version we are talking about. If we...

Async operations in JavaScript

Actually, JavaScript is basically a synchronous, single-thr...

Native HTML: Dialog boxes

I have added a comment to your proposal.

TIL: JavaScript replace() command with callback

Yes, replace with a callback is pretty powerful. However, k...

Native HTML: Dialog boxes

It's a small trade-off, as far as I'm concerned. In the wo...

Native HTML: Dialog boxes

I dislike the dialog element a bit, because it is unusable ...

What’s your favorite JS interview question?

What's your favorite addition to ECMAscript?

How to shift array position in vanilla JavaScript

How about const lastToFirst = _ => ($ => [$.pop(), .....

How to shift array position in vanilla JavaScript

Also, that would change the original array, which is not th...

How to shift array position in vanilla JavaScript

Why not use a really simple solution with plain ES5? fun...

Checking if an input is empty with CSS

Since pattern works like new RegExp('^'+pattern+'$'), this ...

Is Jira an antipattern?

My squad adopted jira as our sole board 4 months ago as an ...

5 CSS tips you didn't know you needed

A CSS trick with an effect on JS: pointer-events: none will...

Why Facebook's api starts with a for loop

a script tag will basically send the same request that wou...

Semi colons;

While you can write JS code without semicolons, you'll run ...

Pro-tip for `mouseenter` & `mouseleave`

If that doesn't help, also check for pointer-events: none; ...

JavaScript: Logical operators and Boolean Values

The bitwise operator ^ (XOR) can also be used to evaluate i...

How TF Does XSS Work?

basically, XSS means that you can inject stuff through the ...

Why Facebook's api starts with a for loop

I did something similar, but I used location.href=... to re...

Is coding easy?

Coding is actually easy, but to write code that is maintain...

How can you swap two variables without using a third?

Basically, it works like this (x64 assembler): mov rax, [m...

If you could install only one VSCode extension?

code.visualstudio.com/blogs/2017/0...

If you could install only one VSCode extension?

I'd create a pack extension of all the extensions I need an...

Async React Basics with Redux-thunk & Redux-saga

Thanks for the nice article. Since you're already familiari...

Mini Quiz: Javascript Scoping

Depends on whether you 1) fix the code (you're missing a co...

In defence of vanilla JavaScript

Some day, we'll reach a state where all those frameworks an...

Why is React a library and not a (simple) framework?

I think you confuse react with the whole ecosystem around it....

Britain in the 70s killed its tech industry because of sexism

Damn autocorrect... :) There's another tragedy looming ahe...

Britain in the 70s killed its tech industry because of sexism

Even worse, one of the fathers of modern computing, Alan To...

How can you swap two variables without using a third?

Since xor and subtraction were already mentioned, may I chi...

REST IN PEACE JQUERY

Actually, the main reason why jQuery is being phased out is...

A JavaScript Haiku

if (code_makes_no_sense()) { delete everything.you_wrote;...

Operations on power of two numbers

Ah, that's true, I missed that.

Improve your reds

The same is true for JavaScript. Jest (jestjs.io/) is espec...

JavaScript: In one word

There's a narrow path between humor and stupidity. This one...

Can editor make you a better developer?

One of the main things that makes you a good developer is e...

Operations on power of two numbers

Your isPowerOfTwo-Function can be even more simplified: ...

Why isn't this unit test catching an error from this async/await function?

In Jest it is even simpler, you just need not forget expect...

We don't need a ternary operator

A condition can obviously be false, but I guess that's not ...

How do you enforce better code and style?

It seems that one of the main points of a code review had b...

We don't need a ternary operator

You basically just replaced condition ? if_true : if_false ...

What makes a good frontend developer?

Those are the basic skills, but to be a good front-end deve...

How would You Handle Dirty Code?

if (!dirtyCode.works || dirtyCode.needsToBeChangedForCurr...

How would you define high quality code?

High quality code is Maintainable: it must be readable, u...

The Definite Guide to Pick the Correct Music While Working

I'm missing classical music in that list. For example, Bach...

Keeping Your Code Simple

You're right.

Keeping Your Code Simple

Yes, the performance is worse. But unless you need the solu...

Keeping Your Code Simple

Sometimes, there's an even simpler solution: const strs ...

How do you convince a client to a static website?

You don't sell them a static website, because that sounds l...

What do you think about the ternary operator?

In it's simple use, the ternary operator is rather helping ...

Accessibility For Beginners with HTML and CSS

Yes, it is a shortcut to empower users who rely on keyboard...

Accessibility For Beginners with HTML and CSS

You can also let power-users "see" it when they activate it...

loading...