There are a couple of ways to convert a string variable to a boolean variable in Javascript. However, when doing this, you have to be kind of careful: it’s kind of easy to mess up this sort of logic and doing it wrong can result in some nasty bugs. So, in order to save you a headache or two, I’ve detailed how to do it properly in this article. Read on, if you’re interested.
…well, revolutionary and amazing to me, anyhow. Like most Javascript programmers, I usually use a for loop to iterate through my arrays, a method which typically works pretty nicely and doesn’t really have many drawbacks. However, I recently discovered another method which takes a tad less typing while maintaining the same functionality–the forEach loop. It’s quite handy and you don’t have to declare a bunch of variables to loop through an array.
Javascript’s little-known do-while loop
Many Javascript programmers are familiar with the while loop, which executes iterates until a given condition evaluates to false. It’s a pretty handy construct and can provide the fastest loops in the Javascript world (if used properly). However, there is a drawback. If the given condition evaluates to false immediately, the while loop will not run even once. This is because the while loop’s condition is evaluated before executing the code within the loop. “Oh well,” you say, “if that’s the case, then too bad, right?” Wrong.
Top 8 Javascript learning tools
Javascript is a complex and multi-faceted language, and can be hard to learn properly. I’ve found quite a few invaluable tools that have helped me along my Javascript-learning journey, but some of them have been a little hard to dig up and others aren’t very well-known. To save you the pain, I’ve scrounged around and pulled together a list of what I’ve found to be the most useful Javascript learning tools. Enjoy!
Javascript is an infamously easy language to program in. However, just because something works doesn’t mean you’re doing it right. Oftentimes, programmers will write a script to provide functionality they need and then leave it as soon as it’s working. Don’t be like those guys: read this tutorial on Javascript optimization (or at least skim it!) and apply the techniques listed here in your code. Your users will thank you.
Javascript has many ways to concatenate strings, and while the standard method provided is useful much of the time, it’s good to be aware of the other methods that exist. In this article, I’ll be talking about the three most prominent ways to concatenate strings, which is best, and why.
There are a number of ways to check if a variable is undefined, and not all of these methods are created equal. Some of them work half of the time; some of them are just plain wrong, and one method stands above all others in usefulness. In this (somewhat lengthy) article, you’ll find out which is which– and why! If you just want the “right” way to check if a variable is undefined, scroll right to the bottom, where I show you the proper method to do this sort of check.
There are several ways to convert a string to a number in Javascript. In this article, we’ll take a look at some of the most common ones and cover the pitfalls and advantages of each.
Improving on Javascript’s random numbers
Javascript’s lack of a good random numbers function is something that has always bothered me. No, I’m not talking about an extremely complex seedable psuedo-random number generator that optionally generates numbers from static interference in the Earth’s atmosphere or radio waves or whatever “real” random number generators do (see random.org for that). I’m simply talking about random numbers that are actually useful– e.g. random numbers between two other numbers, or what are called ranged random numbers.
If you need to change or assign a value to the onclick attribute of a DOM element, you have two options; you can use either plain Javascript or the popular jQuery library. In this article, we’ll take a look at both methods and some common mistakes that are easy to make.