#JavaScript Tutorial#
What is Javascript Javascript is a scripting language used in web development mainly to enhance the user interface of the website to make it more dynamic and friendly, there is a huge amount of cool things you can using this so I do recommend taking notice of it. This is a hard language to grasp but crack into it and you will be amazed with the things you can do with it. The Syntax Okay so lets have a look at the syntax of javascript, its a very different language, if you have done some kind of programming before you will recognise some traits most languages share. If not don't worry I will explain all that we go through. var text = "sometext"; So this is a very basic level of javascript I made as an example to show you what it looks like. How to use it Now that we have seen how the javascript syntax works we will learn how and where we can use it in our html pages. Now the most common way of using javascript is puting it in an external file like css. We can also put it in the head tag and body tag.
<script type="text/javascript" src="source.js"></script> and this is how we implement javascript inside the HTML page itself <html> Outputting Text So lets have a go at writing some text using javascript, here is the code to do that document.write("Hello World"); We will be looking into how this works later in the javascript tutorials. Variables Now we move onto Variables, these are pieces of data that can be assigned a value and that value can be changed at any time. var text = "Hello World"; the var keyword is used to state
that we are declaring a new variable, text is the name of the variable that we
are creating and hello world is the string value it has. The number variable
has the value 10 assigned to it. If Statements if statements are used for when we need to check if a condition needs to be met so lets have a look at an example of an if statement in javascript var text = "hello"; Okay lets break this down to understand what is going on here at the top we declare a variable called text and assign it a string value of "hello" next we check if the variable texts value matches "hi" if it does the page will write "hi" and the else means if there is no match then run what is in the else so bye will be outputted to the screen. |