JavaScript Basics: Comments, Variables, Events
JavaScript Basics: Comments, Variables, Events
JavaScript Summary
The comments:
There are two ways to write a comment.
Single-line comments: they are placed at the end of the line, after //
Example://comment
Multi-line comments:
they are placed between /* and */
Example :/*comment*/
Place the code in a separate file with the .js extension. In this case, you need to create a file.
.js file that contains the JavaScript code we will use.
Example : <scriptsrc="[Link]">
</script>
In an HTML tag, associate an event that will trigger the script
Example : <ponclick="alert('Hello!');"/p>
The variables
Vara=20 local variable
a=20 global variable
The concatenation
Age=18 ;
alert("Vous avez " + age + " ans") ; //affiche :vous avez 18 ans
Use of function
The declaration of a function in the header of the page, between the tags
<head> and </head>.
functionnonfunction( parameters)
{ Traitement ;}
Function call: functionName(parameters)
TIC 1
DkhilInes STI
Conditional Structures
If (condition)
{ }
Else
{ }
switch(selector)
{
casevaleur1: traitement;
break;
casevaleur2: traitement;
break;
…
default:traitement;
break;
}
Iterative structures
while(condition)
{ instructions }
do
instructions
while(condition);
The operators
In algorithm In JavaScript
A=A+ 1 A++
A=A+ X A+=X
A=A- 1 A--
A=A- X A-=X
If (a = b) IF (a== b)
If (a ≠ b) IF (a != b)
ET &&
OU ||
A MOD B A%B
ICT 2
DkhilInes STI
ICT 3
DkhilInes STI
TIC 4
DkhilInes STI
Objects in JavaScript
ICT 5
DkhilInes STI
ICT 6