locutusjs/locutus

Dead code in base64_encode?

codemasher opened this issue · 4 comments

No, it's not dead code. It's used only in browsers which don't have built-in window.btoa function.
In other words, this condition is true

if (typeof window !== 'undefined') {

and this is false

if (typeof window.btoa !== 'undefined') {

The code could probably use a small refactor/restructure to make it more clear.

Nope. The condition

if (typeof window !== 'undefined') {

is truthy, so we go inside the IF block. It has a nested IF, which - when falsy - doesn't do anything and the code continues below the IF...ELSE statement.

Ok, got it - i'm dumb :D