locutusjs / locutus

Bringing stdlibs of other programming languages to JavaScript for educational purposes

Home Page:https://locutus.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dead code in base64_encode?

codemasher opened this issue · 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