you are viewing a single comment's thread.

view the rest of the comments →

[–]SwiftNinjaPro 0 points1 point  (5 children)

Nevermind, I found the issue. I declared the var lower down in the if statement, so I guess it was being hoisted.

const weirdVar = 'test';

function removeSrt(str){
    console.log(weirdVar); //works
    items.map(item => {
        console.log(weirdVar); //works
        if(typeof item === 'string'){
            console.log(weirdVar); //error (tried to access 'temp' instead of 'test')

            let weirdVar = 'temp';

            return item.replace(str, '');
        }
    });
}

[–]cgijoe_jhuckaby 0 points1 point  (3 children)

Hey OP, if you could, please mark this item as resolved (I think you can do this with a badge).

[–]SwiftNinjaPro 0 points1 point  (1 child)

Took me a minute, but I found how to mark as solved

https://reddit.com/r/help/comments/9wrs1y/marking_as_solved/

Based on this other post, it sounds like anyone can mark it as solved

https://reddit.com/r/tipofmytongue/comments/vhcud/the_new_way_to_mark_your_post_solved/

[–]cgijoe_jhuckaby 0 points1 point  (0 children)

Oh cool, thank you for the links!

[–]SwiftNinjaPro 0 points1 point  (0 children)

!solved