Skip to main content

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. Hence, the motive to tweak impossible situations. Don't try it with Strings in JavaScript. Strings can't be changed in JavaScript because they are immutable. So, the code below not working has nothing to do with my father not wanting my name changed but everything to do with the fact that JavaScript won't just let you mess with a QueenπŸ’ƒπŸΎ.
Now that you know facts don't change. Feel free to open your console. Cheers!

Comments

Post a Comment

Popular posts from this blog

Experiences applying to Outreachy

Guess what! You are not the only anxious one! Applying to  Outreachy  was challenging for me too. I enjoy learning. I was motivated to apply because I saw an opportunity to grow while working on products that are in use by hundreds of thousands of people. I was hell-bent on participating. "We help newcomers to Free and Open Source Software" - this sentence caught my attention on the application page . The thought of making contributions to projects in the Free and Open Source Software (FOSS) communities got me excited. Ask! Times when you are not so sure, are great for questions. So are times when you do not even have clues of what you are to do. Ask questions when in doubt. That way, you don't spend too much time in the "Confused" state.  Google  (or any other search engine)  is your friend. Make out time to interact with it. Also, make it a habit to reach out to your mentors with updates, questions, and blockers. Outreachy accepts people who are new t...

Modifying Expectations

It is very fine to modify your expectations... Initially, the estimated and actual completion date for my internship project was not specified. Resource estimates had 100 to 200 hours for writing the tests. So far, I have been able to meet some goals. Some of them include me being able to: learn the existing codebase test some success and failure scenarios for the edit , protect , rollback actions learn the basics of integration testing learn how to write tests using mocha learn the basics of the chai assertion library learn some vanilla javascripts fundamentals In the first half of my internship, I have been able to accomplish the goals listed above plus some extra learnings like:  Promises, async/await concepts technical writing team work open source contribution Setup took longer than expected but the progress since setup improved greatly. It took way longer than expected because I had no understanding of  docker  and some other technologies ne...