Hello, what would the .length for numbers be, I tried assigning a variable to a number and then putting the variable in the console.log but it returns undefined, thanks fairly new to this.
Numbers are exact values that don’t have a length. Sure they have numeral characters, etc., but as objects they have no length. Further to this, numbers are not iterable.
We might hope there is, but the truth is we need to devise an algorithm or special method for this purpose. At this early stage it may be too soon to explore this question.
Take for instance the String method, .split(). This method will take any string as a separator, then splits its string on that separator and returns an array of strings.
const words = 'Teaching the world how to code'.split(' ')
In the above, the separator string is a space character. The returned array is,
Notice the spaces are now removed. The separator is dropped, and only the characters on either side are retained. Note how many words are in the array. Six, which means there were five spaces in the original string.
Anyway, as stated this may be too soon to expose and explore such methods, so don’t go down this path, just yet. It will surface, shortly.
Hi everyone! I have a question. Is it the necessary to use ‘hello’.toUpperCase (). to put something in capital letters or can I just put “HELLO”? Thanks!
What we write directly in our code is literally up to us, pun intended. There is no need to call upon the string method to convert case since we’re typing it in, anyway. Where it will matter is when we are working with random program generated data or user inputted data. Our program may have to conform to some standard or desire of the author. If the need is to have all user input in uppercase, then we don’t trust the user and include the hard coded instruction,