Coding Support
Would you like to react to this message? Create an account in a few clicks or log in to continue.

JavaScript Tutorial

Go down

JavaScript Tutorial Empty JavaScript Tutorial

Post by Scarlet Sun Jul 26, 2015 1:22 pm

Hello there peoples, it's me Scarlet. Now we'll start learning JavaScript, step by step.

Code:
var Cat = {
 // an empty space.
};

"Wait.. I didn't understand that!!!" yes, of course you do! I'll explain. We've just declaring a new variable containing a JavaScript Object Literal. Maybe I'd confuse you a little but don't worry! This tutorial might help you understand what is Object Literal. Oh btw an object literal must end with a semicolon (Wink.

What?! Our cat can't breath!?
Let's safe our cat!

Code:
var Cat = {
 breathe: true
};

That's just close! But I know, you guys are currently reading this post with the face "what are you doing??" well, I've just make a new property called "breathe" and set a value into the property. The value of the property "breathe" was "true", right? Welp, you can just set it into "false" to bring the cat's death. This "true" and "false" was often called "boolean". It's useful for script disabling, etc etc. But it's for higher lesson.

But wait.. there's something odd..
Our cat didn't have a name and age!!!

Well then, let's give it a name and remember when our cat were born.

Code:
var Cat = {
 breathe: true,
 name: 'Felix',
 age: 3
};

There are a few new things right? I know.
First, a comma. A comma was often used to separate a property.
Second, letter Felix wrapped inside single quotes. The letter wrapped inside single/double quotes was often called as a 'string'.
Example:

Code:
'Hello World!' // this is a string
"Hello World!" // this is also a string

Third, a number. Yes, a number. Well, be careful, a number and a string wasn't the same thing. No not a letter wrapped inside a single/double quotes, I mean a number wrapped inside a single/double quotes.

Code:
3 // this is a number
'3' // this is NOT a number. this is a string

Well, to prove that 3 and '3' (3 with a quote) was different, let's diff something more.

typeof, often used to check for types of... Anything. Yeah, anything.

Or you can set an if statement like this.

Code:
if(3 === '3') {
 alert("It's same.");
}else{
 alert("Not the same.");
}

After doing that.. You can remove the code. It might causes insufficient storage space Razz
Scarlet
Scarlet
Admin

Member Title : Classy Person
Posts : 28
Join date : 2015-04-16

https://codingsupport.darkbb.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum