Loading
Lesson 03
Courses / JavaScript for Complete Beginners
Logging a Message to the Console using JavaScript in the Browser

Video Transcript

Welcome back! So now let's jump into JavaScript. So for this video I'm gonna be using Firefox. You can use any of the browsers we mentioned before. All we need to do is open up the web console or JavaScript console or whatever it is that your browser calls it. Okay so now we're here. Let me increase my font size so you can see better. So we are here and we can type commands here and those will be interpreted by the JavaScript interpreter here. So let's start with a first command. We're gonna print a message to the screen, in this case this white space area here. We're gonna type the following. Let's type with me. It's console then you type a dot. Log. Okay so we're gonna log a message to the screen. Now let's say hello world and you place the hello world between two single quotes. Okay so you say console.log and you open parenthesis, single quote, whatever message you want to say. In my case I just said hello world. Close the single quote here. Don't forget then you close the parenthesis. Okay now we're gonna type this. Enter and there you go. It printed the message hello world to the JavaScript console. Okay so that's our first statement in JavaScript. So I'm gonna explain a little bit what's going on here with this statement. Don't, you don't have to understand everything right away. I just want you to learn and hear this terminology that I'll be discussing. Okay so what we have here is the message right hello world or whatever you typed. This message here is placed under single quotes. So this guy right here is called the string. So in the world of programming if you have like some sort of text you know you call them strings like strings of characters. If you think of these characters together forming a sentence forming some text they're called strings. Okay so strings typically appear in quotes. Okay so we have hello world in this case single quotes. There are other kinds of quotes you could use double quotes, back tick in the world of JavaScript but I'll stick with the convention for now of using always single quotes. Okay so we have a string and this string has the text hello world and then we do this thing called console log. Console log, so what are you doing here is you're calling a function. This function is called log and it does what it says it does. It logs a message to the screen to the console in this case. Okay so log is a function. So to the function you're passing an argument. In this case is the message. You're passing the function this argument and the function will do something with that argument. In this case it's taking this message and printing it to the console. So that's what functions do. Function will take some input, some arguments not necessarily just one it could be multiple and then it's going to do some processing and ultimately you're going to get an output. You're going to get something back. In this case what it did was just print the message to the console here. You see the second line that's the purpose of the console log function. It does log. Okay now log functions are part of the console objects and that's a little bit more complicated but you don't have to worry about these terms. Like I said before I just want you to get started here in these terms so you can internalize and better understand them along this road, this journey that you're learning JavaScript. So all these terms will become clear as you go on you continue your journey. Okay so that's it. Now I have a challenge for you. I want you to print something to the console. I want you to print your name. So how would you do it? I'll give you a couple seconds if you think about it can pause the video then when you're done we're going to go on and do the challenge. Alright so how did it go? So we're going to print something to the screen to the console. We're going to say console and I'm going to say dot log and then what is the string here? Two single quotes and I'm going to say I don't know. I'll say my name. You can say your name. Okay so my name is a string. It's being passed as an argument to the log function. Notice functions always have the opening and closing parentheses. Okay so when you see parentheses think of function. Okay the log function is part of the console object which has a function to console has many functions. One of them is log and to log to the console. So it's related. Alright so there you go console log and you are going to get your name here. Alright so this is it for this video. Hope you liked it and see you next time. Bye!
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: