JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Using For Loops with Arrays

Matthew Netherton
Matthew Netherton
2,702 Points

What does the follow code do exactly? What role does it play in the overall scheme of things?

Why do we include the following function?

function print(message) { document.write(message); }

I tried cutting it out, and when I did, the array didn't print to the website. But looking at it, I can't figure out what it does?

Anyone?

1 Answer

Christopher Gardner
Christopher Gardner
12,347 Points

This code would just print the passed message to the document.

function print(message) { document.write(message); }

print("Hello");
// prints Hello to the document

In the grander scheme of things, this could be useful if you just wanted to create a function to write things to the console for testing, and don't want to type "console.log" over and over.

function print(message) { console.log(message); }

print("Hello");
// prints Hello to the console

Hope this helps!