Introduction to Javascript | Part 1

This tutorial is intended as an introduction to javascript for those with atleast a basic understanding of HTML and CSS

In this first part of the tutorial I introduce you to variables and a couple of inbuilt javascript functions

So what do we mean by variable?

A variable is a way that we can store data for use and manipulation throughout our program.

In javascript a variable can be either a numerical value, a string of characters or a boolean (true or false)

We can define a new variable as follows:

Now let's look at how we can then use the variables. To do this I'll introduce 2 inbuilt function alert().

To test this out we can add the javascript to the head section of our HTML doc.

We surround the script in the following tags to let the browser know that the contained code is javascript

We must be carefull when naming variables that we do not use any of the reserved keywords. You may want to copy the following list for future reference.

abstract
boolean
break
byte
case
catch
char
class
const
continue
debugger
continue
default
delete
do
double
else
enum
export
extends
false
final
finally
float
for
function
goto
if
implements
import
in
instanceof
int
interface
long
native
new
null
package
private
protected
public
return
short
static
super
switch
synchronized
this
throw
throws
transient
true
try
typeof
var
void
while
with

These keywords are all either part of the javascript language itself or are reserved for future use in the language

It is also worth noting here that javascript is a case sensitive language.

Javascript keywords are always in lower case

Similarly to CSS we can use javascript to set the style of an element by accessing its id attribute. This becomes extremely usefull later when we learn to write functions as we can change styles dynamically.

In part 2 we will learn some techniques for manipulating the different data types (number and string)

tags

Comments:

Featured Script

PHP Send this page to a friend script
as the title suggests you can add this script to any of your pages and and it will allow your visito... (read more)