11. behaviour.js

Since we’re only touching on JavaScript at this stage my explanations will be fairly brief. Here’s a screen capture of the “behaviour.js” file from the template:

The behaviour.js JavaScript file

The "behaviour.js" JavaScript file

This file may not have many lines but it involves understanding quite a lot. JavaScript is a programming language and so having some knowledge of programming is definitely a benefit…if you don’t, that’s okay I’ll try to explain it at a level that everyone can understand.

Line #01: “var
The word “var” stands for variable and is a way for any programming language (not just JavaScript) to remember something. On it’s own though it’s useless, once you’ve written the word “var” you then need to declare an actual variable…

Line #01: “messageV
This defines a variable called “messageV“. When naming a variable it’s best to follow some kind of protocol and so in JavaScript when you want to make a variable, feel free to call it whatever you like (no spaces or weird characters though) just make sure you include a capital “V” at the end to indicate to anyone looking at your code that it is a variable.

Line #01: ” =
Now we’re telling this new variable to have a value. In our case, that value is quite large, in fact it spans Line #02Line #10! Inside all those lines you can see we’re putting words, or what in programming terms are often referred to as, “strings“. The plus symbol at the end of each of those lines simply allows us to wrap strings onto the next line in our source code (rather than having a really long line). Notice also that the final¬†character you see¬†when we’ve finished all those lines is a semi-colon…this is an important element to JavaScript.

Line #12: “alert
The “alert” function is what pops up a window in a browser. Inside our alert you can see we’ve put the name of our variable, “messageV“. Hopefully it’s not too big a leap to realise that this means JavaScript will pop open a window showing the contents of our variable!

JavaScript is a very large language and adds a very complicated layer to your web design. If you’re interested in learning more check out one of my other tutorials.

Leave a Comment

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>