Hi person who is reading this tutorial! Thank you for clicking on this
Ok! So, to make a comment all you have to do is write two slashes (
//) and put what you want to write in your comment after that!
// This is a comment! // This is another comment!
For multi-line comments, you have to put a slash and a star to start the comment and to close it you have to put a star and then the slash.
Comments don't have an output because they are just text in your code.
Ok, so if you know some Python, then you might know that to write something in the console you have to write
console.log("what you want to write").
You can also put in numbers in a
So strings are just what they sound like; strings of characters! Strings always have to be enclosed in either double quotes (
"") or single quotes (
'') but they can't be mixed like this:
'this is a string" or like this:
"this is a string'. This is an example of the right way:
"this is a string" 'this is also a string'
I wanted to go over strings because they are very important when you want to write something or sometimes give a value to something.
var. Then after you write
var you put a space and then you can write something like
age and that will be your variables name. After you name your variable, you have to put a space and then an equal sign (
=) and then another space. When you do that you have to write in a value for the variable. If you want your variable to be a number, then just put in that number. If you want your variable to be a string, then you need to put in either double quotes (
"") or single quotes (
'') like we talked about earlier in the "Strings" section. The entire format is shown below:
var variable_name = number; // This is for numbers var variable_name = "some text" // This is for strings var variable_name = 'some other text' // This is also for strings
This is an example of announcing some variables and printing it:
var myNum = 10; console.log(myNum);
Notice that when I put the variable in the
console.log();statement, I don't use any quotes.
document.write(); statement is basically like
console.log(); except that instead of printing something in the console, it writes something in your document.
document.write("Awesome stuff!"); document.write(123456789);
Awesome stuff! 123456789
Just like the
console.log(); statement, you can put a variable on it.
This is gonna be a very small section and I decided to squeeze it in. I wanted to tell you that you can declare multiple variables in one line if they are the same data type.
var myNum1 = 1, myNum2 = 2, myNum3 = 3, myNum4 = 4, myNum5 = 5; // Declaring multiple number variables var myVar1 = "HI", myVar2 = "hi", myVar3 = "Hi", myVar4 = "hI", myVar5 = "hi!" // Declaring multiple string variables
Since I didn't print the variables, there is no output