There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Just a quick question: why is there an option to declare an array without assigning it to a variable. When would we need to do that, if at all? See code below which compiles without error:
I am in lesson3/12 in arrays (Java Script Syntax 2).
In the counting of index positions in the ‘Hello World’ code, the 6th position was the W. Does that mean that the ’ ’ are also counted and that ’ got the 0 position? Otherwise was it the empyy space between the words that got the 5th position?
0 1 2 3 4 5 6
H e l l o W o
const hello = ‘Hello World’;
console.log(hello[6]);
// Output: W
You will find this to be the case when the system compiles your literals. It is not an issue, though. It has to do with the string literals being primitives that need to be given an object wrapper by the interpreter. It always uses single quotes in this step.
Thanks for the quick response and for supplying an understandable explanation as always. Since the lesson gave me a pass on the original code I figured it was not an issue, but I wanted to ask out of curiosity.
I also tried putting the array elements in single quotes:
const hobbies = ['Football', 'Tennis', "Wine'];
which also prints in single quotes.
console.log(hobbies); // prints [ 'Football', 'Tennis', 'Wine' ]
hi, i have set ny array but it still prints to the console with the square barackets i.e [‘jesus’,‘car’,‘9’]…is this still okay and how can i avoid those brackets being printed in the console
If we log an array, the actual object is printed to the display, including the brackets and quotes on strings. To log just the values we need to iterate the array. This will be covered once you get to the unit on loops.