As a developer learning new skills is a necessary part of self improvement as well as a great way to diversify your skill set. Different programming languages open different doors and depending on the task at hand you may need to call upon a variety of different languages to achieve a specific set of goals.
One of the ways I like to learn new languages is by writing about it. As I write I further solidify the the knowledge in my own mind as I have to take each part step by step and test each state to ensure it is indeed correct.
Like all programming languages its important to have a firm understanding of the fundamentals. Without them you will waste a lot of time when it comes to writing your code.
Data comes is various types and you should be able to recognize the type of data you are handling.
Strings– are sequences of characters
0-9as well as symbols written within quotes.
Numbers– are quantities
0-9and are written without quote.
Booleans– are either true or false.
Discovering the length
The string length property allows you to take any string and measure the number of code units it represents. (That includes spaces)
There are a number of useful reasons to want to know the length of a string. For example an empty string will return 0, otherwise it will have a value. This gives us at least 2 states which can be used to perform (true/false) conditional statements not unlike a standard if/else statement in PHP.
You may also want to handle data differently according to its length. Perhaps a contact form input field is to be limited to X amount of characters or should be at least a certain number of characters.
For example; Twitter only allows 140 characters and will have a way to calculate the length of the string in order to ensure the tweet falls within the constraints set by Twitter.
var string = "Your tweet represented as a string"; var tweet = string.length; console.log(tweet); // returns 34