30 Days Of JavaScript

Day 1: Simple Types

Lesson 1: Console.log()

No matter what programming language you are using there will be the concept of printing something out and JavaScript is no different.

In JavaScript we print to the console. It's like a hidden world of code output that you as a user don't see, but it's vital for developers to help them write code and build the awesome sites and apps that you use in your browser.

Since JavaScript runs in your browser you can print to the browser's console. There are many different browsers and all of them have there own developer tools.

For now though I want to keep you focussed on the language of JavaScript rather than dealing with your browser. So I have included a mini coding environment (playground) for you to use, acting as a code editor, browser window and console all in one.

Take a look below

Change the line console.log("hello"); to console.log("hello world");.

Notice that as you type, the console on the right prints your output.

If you want to clear the console output click the icon and if you want to refresh the code back to the starting example you can click the icon.

Have a play around with the playground, see if you can log hello world across two lines with two console.log(``); lines.

What's actually happening here?

So console is an object that lives in you browser, and it has things it can do. Like log so we are calling log on console and then telling it what we want logged.

The () are special and they are telling the log to do it's thing. So the line:

console.log("hello world") breaks down to us saying "tell () the console object in the browser to log the words hello world"

Outline

Go Pro?

If you upgraded to pro, sign in here

  • About
  • Blog
  • Privacy
Looking to email me? You can get me on my first name at allthecode.co