Look into Editor's Note before editing this page.
Discover the length
To discover the length of a word(number of characters) write the word within quotes. Then write a full stop and the word ‘length’ like this:
Say I use the word “Birthday Cake”, I will type in
- The result will: 13
Now a question might arise inside your head: Why 13? It should have been 12! But you should note that spacing is also counted as a character.
Comments make your program easier to understand. When you look back at your code or others want to collaborate with you, they can read your comments and easily figure out what your code does.
There are two types of comment statements:
As written in name, Single line comment statements are only applicable in one line. But Multi line is applicable as much as the user likes. While programming programmers usually give introduction in Multi line Comment Statements.
On the labs.codeacademy.com Text editor type in your name and find out its length. Also try to add in a comment statement. You can tweak a little bit and try this:
"Any word".length //Hello baby //Stupid SHemurr
- sign represents a statement terminator. It is used to distinguish between two statements.
Suppose I write: "computer".length "stupido".length
I will get a Syntax error . The computer takes them as one statement and gets confused. That's why we need a statement terminator(;).
Note: Always remember to add in a semi colon after completetion of one statement.
Glitch: If you type in "computer".length "stupido".length into the Text editor (Left side one) it will show an error(as obvious) but if you insert "stupido".length on next line, the editor will automatically insert semi colon after them(though it will not be displayed to you) and on execution it will not show an error.
Cosnole.log() is a print statement for console. Anything that you type in the parenthesis will be calculated and then "printed" on the console. If you insert string, it will print the characters in the string. If you insert an arithmetic operation it will print the calculation's result in console.
- The console usually displays the final result of a program or the end statement's result. But if we want to display(or print) some result that comes in between the run time of program, we use console.log() statement.
- The console.log() can only accept one statement.