class: center, middle, inverse # Javascript ### Introducció llenguatge .footnote[Mateu Yábar] --- # Variables i constants ```javascript const myNumber = 2; let myVarNumber = 2; myVarNumber = 5; ``` ```javascript var anotherNumber = 4; ``` --- # Variables - tipus ```javascript let someVar = 2; someVar = true; someVar = "Hello"; ``` --- # Tipus de dades en JavaScript - Primitius: `string`, `number`, `boolean`, `undefined`, `null`, `symbol`. - Objectes: `Object`, `Array`, `Function` ```javascript let array = [2,3,4]; let object = {"name": "John", "surname": "Queral"}; ``` --- # Strings ``` const s1 = "nice"; const s2 = 'text'; const s3 = `this is a ${s1} ${s2}`; ``` --- # Comentaris ```javascript // I am a comment /* I am also a comment */ ``` --- # Log ```javascript console.log("message"); window.alert("message2"); ``` --- # If ``` let condition = false; if(condition){ console.log("Is true"); } else { console.log("Is false"); } ``` --- # Switch ```javascript const value = 3; let name; switch (value) { case 1: name = "one"; break; case 2: name = "two"; break; default: name = "many"; break; } ``` --- # For ```javascript for (i = 0; i < 5; i++) { console.log(`i: ${i}`); } const list = [1,4,7,8]; for (let value of list) { console.log(`value: ${value}`); } ``` --- # Funcions ```javascript function nomDelaFuncio() { // Codi de la funció } function nomDelaFuncioAmbParametres(parametre1, parametre2) { // Codi de la funció return ""; } ```