1.1 - Output & the Console
Review:
We will be programming in an IDE - several IDE's exist.
We will be backing-up our code to Github, an internet-based version control system.
JavaScript's entrypoint is the top of the script file - you don't need a main() function.
To print something to the console in JS, the command is console.log(x) where x is whatever you want to print.
1.1 - Output & the Console
Output to the user is crucial in programming:
Most programming languages have a console of sorts to print text and numbers.
Very similar formatting can be used in most languages to add new lines (\n) or tabs (\t), etc.
Those are called "escape sequences". To print a slash, you need \\\
JavaScript uses an object called console to print or interact with the console window.
Depending on the version of JavaScript, your console may or may not have the following:
console.log() - similar to a "captain's log" or journal entry, print to the console
console.info() - more for the developer, print potentially important info to the console
console.error() - a specific call to print an error message to the console
console.time(name) - start a timer with the give name (text)
console.timeLog(name) - print the current elapsed time for timer name
console.timeEnd(name) - stop the timer named name
In-Class Practice (lead by the teacher):
Every web browser is built on top of HTML and JavaScript. This means your browser has a console.
Open a chrome browser window and visit www.brash.ca.
Then hit CTRL+SHIFT+J (on a Mac it's OPTION+COMMAND+J)
This will be different for other browsers - if you aren't using Chrome, you're on your own.This should bring up the developer tools and it should have highlighted the "console" tab. The "console" is like the brain of JavaScript, taking commands and giving output.
Click into the console where you see a ">" chevron, this is the terminal (console) waiting for a command.
Type console.log("Hello World!") and hit enter.
Now type into the console document.write("Hello World!") hit enter and see where the output goes.
Try console.time("test") hit enter, wait a bit and then console.timeEnd("test")
❓ What might this be useful for?
Thankfully we won't have to work in the browser's console window for this course!
Today's Task(s):
Read and follow the instructions in "1.1 - Output & the Console"
Did you know?
The skills you are learning in JavaScript transfer directly to about 30 other programming languages. Don't hate on JavaScript - it's an excellent scripting language.