Feb 10
Javascript Tutorial 1
Alrighty class , this class is about to begin! if you could all please find your seats that would be great..
Lets get started!
we are going to go over some basics first.
Script Tag:
- Script Tag
<script type="text"/javascript">
</script>
that my friends is the script tag. notice how i added the type in there. it is proper javascript to do that since it makes the browser read everything better. since there are multiple scripting languages this will tell the browser "HEY! YOUR ABOUT TO READ JAVASCRIPT!"
simple huh? even though
- Script Tag
<script>
</script>
does work its best to get in the habit of using the type.
Got that? Ready to move on?
AWESOME!
Javascript Variables:
Now you can have almost anything as a variable name. obviously like all scripting/programming languages there are certain things you can't have. but you should be able to use common sense on whether you can have it.
lets have an example:
- Variables
var x = 0;
x =0;
alright i just made the variable x there are 2 ways you can do it. if you look through some of the javascript codes on IF or ZB you will notice some codes use either or. both can be fine. however i find it more practical to use var x= 0;
now you dont always have to use a number in the variable. variables can hold all sort of information! like a word or a phrase or even HTML !!
- Variables
var x = 0;
var y = "This is Text";
var z = "<a href=' # ' >link</a>"
now look what is done. variable x is still zero , variable y is text , variable z is a little different variable z has HTML. it uses the same base for the variable with text but using either an opening/closing double quote or single quote. but if you look close enough right after the href=
comes ' # ' now we all know you should have the url encased in quotes. but wouldn't that break the string ( string is this = " anything in here" ) no it won't in this case. anytime you are calling a variable or using innerHTML or document.write ( i will get to innerHTML and document.write in future tutorials) you can use both however whatever quote you choose to use to open it what you can't use in the string itself. Example time!
- Variables ( Wrong Way)
var z = "<a href="#" >link</a>"
so why wont this work? because the browser reads the first double quotes as the start of the string. using the double quotes in the string will tell the browser to stop at the second double quotes. causeing you to have some excess wordage and stuff that errors because the browser doesn't know how to read that. so if you start with double quotes you must end with double quotes. and use single quotes in the middle of the string.
- Variables ( Right Way)
var z = "<a href='#' >link</a>"
var z = "<a href=\"#\" >link</a>"
What did i just do there?! I added some slashes. If you MUST use double or single quotes inside that are the same as what you started/ended with than you must escape them by using the slashes . That will tell the browser to not read it as closing the variable and just read it as quotes inside the string. yeah that might not make to much sense thats why i say use the right way
ok so what have we learned? using variables and script tags correctly.
Whats next Up?
Working with Variables some more, document.write()
- Add new comment:

11:55 AM Dec 8