Javascript #2 : valeurs, types & opérateurs
-
Upload
jean-michel -
Category
Software
-
view
311 -
download
2
description
Transcript of Javascript #2 : valeurs, types & opérateurs
![Page 1: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/1.jpg)
Javascript : Valeurs, types & opérateurs
![Page 2: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/2.jpg)
1. Un programme javascript
![Page 3: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/3.jpg)
1.1 Outils
![Page 4: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/4.jpg)
Moteurs JavaScript pour le développement
Navigateur JSFiddleConsole
![Page 5: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/5.jpg)
Les outils du développeur Javascript (1)
FireFox Chrome Chrome Canary
![Page 6: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/6.jpg)
Les outils du développeur Javascript (2)
Sublime Text BracketsAtom.io
![Page 7: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/7.jpg)
1.2 code javascript ?
![Page 8: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/8.jpg)
Un fichier javascript
alert("Bazinga"); alert("Im not crazy."); alert("My mother had me tested");
![Page 9: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/9.jpg)
Quelques commandes
alert("Suit up!"); console.log("Haaaaaave you met Ted?");
![Page 10: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/10.jpg)
Commentaires
// Single Line Comments !/* Multi-line Comments */
![Page 11: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/11.jpg)
1.3 Où mettre du javascript ?
![Page 12: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/12.jpg)
JavaScript dans une page HTML (1)
<!doctype html> <html> <head></head> <body> <script> alert('Hello world!'); </script> </body> </html>
![Page 13: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/13.jpg)
JavaScript dans une page HTML (2)
<!doctype html> <html> <head></head> <body> <script src="hello.js"></script> </body> </html>
![Page 14: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/14.jpg)
2. Valeurs
![Page 15: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/15.jpg)
2.1 Nombres
![Page 16: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/16.jpg)
Définir un nombre
890 // entier 87.90 // décimal 2.9e3 // 2.9 * 10 * 10 * 10
![Page 17: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/17.jpg)
Maximum & minimum (1)
[-253 … 253]
![Page 18: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/18.jpg)
Maximum & minimum (2)
9007199254740992 + 1 == 9007199254740992; // true 0.2 + 0.4 == 0.6000000000000001; // true 1/7 + 1/7 + 1/7 + 1/7 + 1/7 + 1/7 + 1/7 != 1; // true
![Page 19: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/19.jpg)
Nombres spéciaux (1)
Infinity // plus l'infini -Infinity // moins l'infini NaN // Not a Number
![Page 20: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/20.jpg)
Nombres spéciaux (2)
Infinity + 1 == Infinity // true Infinity - Infinity == NaN // true 0/0 == NaN // true NaN + 1 == NaN // true
![Page 21: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/21.jpg)
2.2 Chaînes de caractères
![Page 22: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/22.jpg)
Définir une chaîne de caractères
"When I get sad I stop being sad and be AWESOME instead." 'True story!'
![Page 23: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/23.jpg)
Caractère d'échappement
"There is only one god and his name is Death. And there is only one thing we say to Death: \"Not today.\"" !"A bear there was, a bear, a bear!\n All black and brown, and covered with hair!\n The bear! The bear!\n Oh, come, they said, oh come to the fair!\n The fair? Said he, but I'm a bear!\n All black, and brown, and covered with hair!" !"hodor \\ hodor \\ hodor"
![Page 24: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/24.jpg)
2.3 valeurs spéciales
![Page 25: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/25.jpg)
Booléens
true != false // true true == 1; // true false == 0; // true
![Page 26: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/26.jpg)
Null & Undefined (1)
Undefined : primitive value used when a variable has not been assigned a value
Null : primitive value that represents the intentional absence of any object value
![Page 27: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/27.jpg)
Null & Undefined (2)
undefined == null // true undefined != 0 // true null != 0 // true
![Page 28: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/28.jpg)
3. Opérateurs
![Page 29: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/29.jpg)
3.1 Manipulation
![Page 30: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/30.jpg)
Arithmétique
3 + 2 == 5; 3 - 2 == 1; 3 * 2 == 6; 3 / 2 == 1.5; 3 % 2 == 1; !3 * 2 + 2 == 8;
![Page 31: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/31.jpg)
Concaténation
"If you're committed enough, you can make any story work." + " I once told a woman I was Kevin Costner, and it worked because I believed it." + " - Saul Goodman »; !// If you're committed enough, you can make any story work. I once told a woman I was Kevin Costner, and it worked because I believed it - Saul Goodman
![Page 32: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/32.jpg)
3.2 Comparaison
![Page 33: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/33.jpg)
Numérique
3 > 2 // true 3 < 2 // false 8 == 9 // false 8 != 9 // true 9 >= 9 // true 9 <= 10 // true !9 == '9' // true 9 === '9' // false !'a' < 'u' // true; 'ab' < 'ba' // true 'a' < 'Z' // false
![Page 34: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/34.jpg)
Logique
true && true // true true && false // false false && false // false !true || true // true true || false // true false || false // false !!true // false !false // true !3 + 4 == 7 && 2 * 8 > 10 // true
![Page 35: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/35.jpg)
Ternaire
true ? 'yep' : 'nop' // yep false ? 'yeah' : 'noop' // noop
![Page 36: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/36.jpg)
3.3 Types & transformations
![Page 37: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/37.jpg)
Types de données
typeof 8 // number typeof 9.3 // number typeof NaN // number typeof 'toto' // string typeof true // boolean typeof null // object typeof undefined // undefined
![Page 38: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/38.jpg)
Conversion de type
3 * null // 0 "3" - 1 // 2 "3" + 1 // 4 "cinq" * 3 // NaN "five" * 3 // NaN false == 0 // true
![Page 39: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/39.jpg)
4. Constantes & Variables
![Page 40: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/40.jpg)
Nommer une variable (1)
Aucun espace
Aucun mots clés réservés : break case catch continue debugger default delete do else false finally for function if implements in instanceof interface let new null package private protected public return static switch throw true try typeof var void while with yield this
Aucune ponctuation sauf ‘_’ et ‘$’
Ne doit pas commencer par un chiffre
![Page 41: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/41.jpg)
Nommer une variable (2)
// Syntax valide var a; var b, c; var s_variable; var b2;
// Syntax invalide var 2a; var a:a; var function;
![Page 42: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/42.jpg)
Affecter une variable
// Affecter une variable var a = 8, b = "toto", c = true, d; a = 2; console.log(a); // 2 console.log(b); // toto console.log(c); // true console.log(d); // undefined
![Page 43: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/43.jpg)
Constantes
const a = 8; a = 2; console.log(a); // 8
![Page 44: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/44.jpg)
Merci pour votre attention.
![Page 45: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/45.jpg)
BibliographieEloquent JavaScript - Marijn Haverbeke http://eloquentjavascript.net
Dynamisez vos sites web avec Javascript ! - Johann Pardanaud & Sébastien de la Marck http://fr.openclassrooms.com/informatique/cours/dynamisez-vos-sites-web-avec-javascript JavaScript Fundamentals - Jeremy McPeak http://code.tutsplus.com/courses/javascript-fundamentals
Guide JavaScript - teoli, BenoitL, delislejm, Ame_Nomade, SphinxKnight https://developer.mozilla.org/fr/docs/Web/JavaScript/Guide
Javascript – MAX_INT: Number Limits - Vjeux http://blog.vjeux.com/2010/javascript/javascript-max_int-number-limits.html
![Page 46: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/46.jpg)
Lost - Jeffrey Lieber, J. J. Abrams, Damon Lindelof http://abc.go.com/shows/lost
Crédits (1)
Person of interest - Jonathan Nolan, David Slack, Patrick Harbinson http://www.cbs.com/shows/person_of_interest/
Halt and Catch Fire - Christopher Cantwell, Christopher C. Rogers http://www.amctv.com/shows/halt-and-catch-fire
Utilities terminal Icon - kxmylo http://www.iconarchive.com/show/simple-icons-by-kxmylo/utilities-terminal-icon.html
Breaking bad - Vince Gilligan http://www.amctv.com/shows/breaking-bad
House of Cards - Beau Willimon https://www.facebook.com/HouseofCards
The Big Bang Theory - Chuck Lorre, Bill Prady http://www.cbs.com/shows/big_bang_theory/
Game of Thrones - David Benioff, D. B. Weiss http://www.hbo.com/game-of-thrones
![Page 47: Javascript #2 : valeurs, types & opérateurs](https://reader031.fdocument.pub/reader031/viewer/2022020207/559840b31a28ab04218b45a6/html5/thumbnails/47.jpg)
The Wire - David Simon http://www.hbo.com/the-wire
Crédits (2)
Silicon Valley - Mike Judge http://www.hbo.com/silicon-valley
The Killing - Veena Sud http://www.amctv.com/shows/the-killing
Band of Brothers - Tom Hanks, Steven Spielberg http://www.hbo.com/band-of-brothers