Skip to main content

Posts

Showing posts from July, 2020

Entangled Strings - Some JavaScript wisdom for when you get entangled

I get these Strings entangled sometimes. You gotta know your stuff well enough to speak to computers these days. They don't argue with you. They just do as you type, maybe say in some cases. Let us debug 👩🏽‍🔧 str.charAt(index) !== str[index] in some cases and here's why: str.charAt(index) returns "" if no character is found at the given index BUT str[index] returns undefined instead. Do you even know what to do when you find me? This never logs because I am at position 0 and that's falsy . All you had to do was check for negative vibes. Now, you know I only do positive vibes yea?😏 Let's try this again. We found her! This logs because I check for negativity   instead. Using  str.indexOf(searchValue)   means to expect -1 when the search value is not found or a value >= 0 when it is found. Now, I know you heard stuff about  str.substring(2) === "POSSIBLE" being true. Yes, POSSIBLE is in fact a substring of IMPOSSIBLE. He...