Prose is structured in sentences and paragraphs in the english language. In Javascript we structure our code in lines of instruction and functions.
To create javascript that is easy to understand and maintain the code must be broken into smaller modules. These modules or packages of instructions are called functions and can be called upon to be executed from other parts of your program. Essentially, functions are chunks of code. Enough talk, let’s create a function:
function test()
{
document.write("Hello can you see me?")
}
Note that if only this were within your <script></script> tags, you will not see “Hello can you see me?” on your screen because functions are not executed by themselves until you call upon them. So we should do something:
function test()
{
document.write("Hello can you see me?")
}
test()
The last line test() calls the function, now you will see the words “Hello can you see me?”.
Leave a Reply