Javascript: Difference between revisions
Jump to navigation
Jump to search
Line 51: | Line 51: | ||
* or: || | * or: || | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
cond1 = 1 > 2 && 2 > 3 | var cond1 = 1 > 2 && 2 > 3; | ||
cond2 = 1 < 2 | 10 > 1 | var cond2 = 1 < 2 | 10 > 1; | ||
var myVariable2 = 0 | |||
if(typeof myVariable = 'undefined') { | if(typeof myVariable = 'undefined') { | ||
alert('This variable has not been declared'); | alert('This variable has not been declared'); | ||
} | } | ||
if(myVariable2) { | |||
alert('This variable is empty'); | |||
} | |||
if(cond1) { | if(cond1) { | ||
alert('cond1 is true'); | alert('cond1 is true'); |
Revision as of 14:42, 29 October 2017
Basic
alert/prompt/confirm
alert('Windows Popup text');
prompt('Windows Popup Text and return value entered');
confirm('Display ok and Cancel button and return true or false');
Html Tag
<!DOCTYPE html>
<html>
<head>
<title>Java script Demo</title>
</head>
<body>
<h1>Titre niveau 1</h1>
<script>
alert('your javascript here!');
</script>
<script src="js/app.js"></script>
Variables
var myVariable;
var myVariable = 10;
var myVariable = "some string"; var myVariable = 'some string'; var myVariable = 'it \'s easy';
var myBolean = 10 > 1;
var myOppositeBolean = !myBolean;
Comparison
- Less: <
- Greater: >
- equal (value): ==
- equal (value and type: ===
- not equal: !=
- undefined: == 'undefined'
- function type of variable
alert(typeof myVariable);
Condition
- and: &&
- or: ||
var cond1 = 1 > 2 && 2 > 3;
var cond2 = 1 < 2 | 10 > 1;
var myVariable2 = 0
if(typeof myVariable = 'undefined') {
alert('This variable has not been declared');
}
if(myVariable2) {
alert('This variable is empty');
}
if(cond1) {
alert('cond1 is true');
} else if(cond2) {
alert ('cond2 is true');
} else {
alert('cond1 and cond2 are false');
}