ICT Portion g12
ICT Portion g12
ICT Portion
Grade 12
TECHNOJAVASCRIPT
What is JavaScript?
JavaScript is a computer programming language. It is used to make web pages more interactive.
To interact with a web page by having it respond to user actions . Examples of user actions include
a click of a button, hovering over text, a mouse pointer etc.
The alert box is simply a box that encloses the message you need to pass to the user. The box will
pop up on the browser.
Use the alert box when you need to emphasize a particular message! It will make sure that the
user has read your message.
2
Write a program in JavaScript to Create an alert box
Output:
What is a Confirm Box?
The confirm box comes with two buttons, OK and CANCEL buttons.
The confirm box is used to let the user confirm or verify their action
Output:
What are Comments?
These are explanations for your code. You add the comments within the code to know
the meaning of each line of code.
Your friend/classmate may want to read the JavaScript code that you have written.
How can you ensure that they find it easy to understand your code? You can use
comments.
How to write Comments
To mark a line as a comment, just add two forward slashes (//) at its beginning.
Note that the comment is added within the same file as the JavaScript code, only
that it will have no effect on the results your code returns. For example:
You may want to give long explanations about the code. In this case, the comment
will take up more than one line. In such a case, he can enclose the comment with /*
and */. For example:
/* Hello Alex, this is a comment explaining the code to you. I need to write a program
that prints Hello World on the web browser. I hope you will enjoy seeing my code
work */
5
This code is used to print Hello world
6
What is a Variable?
1. The variable name should begin with either an underscore (_), a letter (either A to Zor ato
z), or the dollar sign ($). From this rule, these are valid variable declarations:
Valid Names
var _name;
var name;
var Name;
var $name;
var name12;
The following are invalid variable declarations in JavaScript:
var 23name;
var #name;
var –name;
var ()name;
2. After the first letter, one can use digits in the variable name. For example:
Valid Names
var name12;
var na23me;
var _name23;
var $name23;
To store the value Alex into our container, we can type the following statement:
You must have noticed that there are double quotes around the value of the variable.
You must have noticed that there are no double quotes around the value of the
variable.
we use the function keyword, write the name of the function ,() then }{
function myfunction(){
}
A local variable is a variable that has been defined within a function, that is, within the { and } of
a function.
For example:
function myfunction(){
var name = "Alex“
}
Global Variables
For Example:
<script>
myfunction(){
}
</script>