Using the JavaScript Console.log
We start working in our application by creating our first init function in our application. As alerts are very retro we will take a look at a more modern and easier way to work within javascript using the Console.log(); in the console we can output information without it even reaching the user - that's really handy and useful so in this video for the most part we cover this topic. Until the more modern browsers we just had no way to output information in a way that is transparent to users but now days its easy and almost fun doing it. In this video we take a peak at how to find the console both on FireFox and on Safari.
Video Transcript
00:00All right, so now that we've set that up,
00:02our next step is we're going to go into our JS file
00:04because I'm working with Dreamweaver CS6.
00:07I could jump right into my JavaScript
00:09just with a click of a button, which is really, really cool.
00:12If you don't have the CS6,
00:13just make sure you open up the 001.start.js file.
00:18And in this file, I'm just going to create a new function
00:20and I'm going to call it init
00:22because we've just created that function.
00:24We called it init.
00:25We're just going to do a really quick test,
00:27although we don't need to, because we know it should work.
00:28I'm going to put here an alert, hello.
00:32And I'm going to open this up inside of my Safari,
00:35but you could open it up in any of your applications.
00:40And you could see that I'm going to get this hello,
00:42which works perfectly.
00:44I could see the same thing in Safari
00:46if I go right into our project.
00:48If I refresh it, I'll get a low.
00:51Now, obviously, I'm not going to do this
00:52in every single browser,
00:53but the reason why I'm showing this to you at this stage
00:56is because I want to talk about
00:57something that's called the console.
00:59And traditionally, in JavaScript,
01:01people used to work with alerts to debug applications.
01:05And if you've worked with other languages,
01:07maybe such as ActionScript,
01:09you probably worked a lot with the trace.
01:11Now, contrary to trace that enables you in Flash,
01:15it enables you to have like a window and output bar
01:17that you could output into it
01:18without the user actually seeing it.
01:20In JavaScript, that was really complicated
01:22for a very long time until the more modern browsers
01:25it enables us to actually output it,
01:27not into an area where the user actually sees,
01:30but to output our information directly to our use,
01:32to our console, into this hidden area.
01:36Now, the way to do that is just by typing console.log.
01:41And then we could send logging information directly there.
01:44So I'm going to type here, hello.
01:46I'm going to save it.
01:47And this time around, you'll see that our,
01:49we don't have any errors.
01:50So let me close that so we could actually see our code.
01:53It's good that we don't have our errors,
01:54but we don't want to hide our code.
01:56So when we're creating our function, log hello,
01:58fantastic that we don't have any errors.
02:00But now if we go into our Firefox and refresh,
02:03we'll see that we're not going to see anything,
02:04which is a good thing
02:05because the user's not going to see anything.
02:07And same is true for our Safari.
02:10Now, OtoChrome has these features.
02:12You're just going to have to dig a little bit deeper.
02:14Inside of Safari, let's start there.
02:17How could we actually see what's going on?
02:19If you go into the develop window,
02:21you'll want to make sure that it's set to be set,
02:24you want to make sure that you're in your Safari set up
02:26to be in developer mode.
02:28Once you are set up to be in the developer mode,
02:30you want to search for the show web inspector
02:34or error console, either,
02:36or they're going to open up a window
02:37that's going to help you see what's going on.
02:39And you could see that in our log,
02:41you could see that we're seeing the hello
02:43that we typed in earlier.
02:44And it even tells us at what line it was typed,
02:47making it really, really comfortable.
02:50All right, so you want to make sure
02:51that you're in developer mode.
02:52And once you're in the developer mode,
02:53now you have access to the console
02:55whenever you want to, whenever you need to.
02:57Same is true with Firefox, only with Firefox,
03:00you have to have an extension plugin,
03:02which is called Firebug.
03:03Once you install Firebug,
03:05you're going to have access to Firebug.
03:07Now, when you have access to Firebug,
03:09you could just right click anywhere
03:10and click on inspect element with Firebug,
03:12even though that's not our goal.
03:14And then you could click into the console,
03:17and you'll be able to see our logging information
03:20inside of the console.
03:21And we're going to be leveraging the console
03:23quite a lot, it's very powerful, very, very useful.
03:27And it's going to obviously make it much easier
03:28for us to debug and test our applications,
03:30even when they go live without our users
03:33needing to worry too much about it,
03:34because it's not going to be something visible
03:36to our users, all right?
03:38And that's all we need to know at this stage
03:40before we could start building our Google map.
03:43Because from now on, anytime that we have an issue
03:45or we want to see something,
03:47we could always trace it out directly,
03:49or we could always trace it out,
03:50logging out directly into our console.
