forked from mouredev/hello-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03-beginner-exercises.js
More file actions
96 lines (87 loc) · 3.12 KB
/
03-beginner-exercises.js
File metadata and controls
96 lines (87 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
Clase 18 - Ejercicios: primeros pasos
Vídeo: https://youtu.be/1glVfFxj8a4?t=4733
*/
// 1. Escribe un comentario en una línea
// Este es un comentario en una línea
// 2. Escribe un comentario en varias líneas
/*
Este es un comentario multilinea
que se extiende por varias líneas
*/
// 3. Declara variables con valores asociados a todos los datos de tipo primitivos
let myBoolean = true;
// Para números enteros y decimales se utiliza el mismo tipo de dato: number
let myNumber = 42;
let myFloat = 3.14;
// strings pueden ser con comillas simples, dobles o backticks
let myStringWithDoubleQuotes = "Hello, world!";
let myStringWithSingleQuotes = 'Hello, world!';
let myStringWithBackticks = `Hello, world!`;
let myNull = null;
let myUndefined;
let mySymbol = Symbol("mySymbol");
// 4. Imprime por consola el valor de todas las variables
console.log(myBoolean);
console.log(myNumber);
console.log(myFloat);
console.log(myStringWithDoubleQuotes);
console.log(myStringWithSingleQuotes);
console.log(myStringWithBackticks);
console.log(myNull);
console.log(myUndefined);
console.log(mySymbol);
// 5. Imprime por consola el tipo de todas las variables
console.log(typeof myBoolean)
console.log(typeof myNumber)
console.log(typeof myFloat)
console.log(typeof myStringWithDoubleQuotes)
console.log(typeof myStringWithSingleQuotes)
console.log(typeof myStringWithBackticks)
console.log(typeof myNull) // typeof null devuelve "object", es un error histórico de JavaScript
console.log(typeof myUndefined)
console.log(typeof mySymbol)
// 6. A continuación, modifica los valores de las variables por otros del mismo tipo
myBoolean = false
myNumber = 100
myFloat = 2.718
myStringWithDoubleQuotes = "Goodbye, world!"
myStringWithSingleQuotes = 'Goodbye, world!'
myStringWithBackticks = `Goodbye, world!`
myNull = {}
myUndefined = undefined
mySymbol = Symbol("anotherSymbol")
// 7. A continuación, modifica los valores de las variables por otros de distinto tipo
myBoolean = "This is a string now"
myNumber = true
myFloat = null
myStringWithDoubleQuotes = 12345
myStringWithSingleQuotes = false
myStringWithBackticks = undefined
myNull = 'Now I\'m a string'
console.log(myNull) // Comprobando que escapé correctamente la comilla simple
myUndefined = 3.14
mySymbol = `Not a symbol anymore`
// 8. Declara constantes con valores asociados a todos los tipos de datos primitivos
const myConstBoolean = true;
const myConstNumber = 42;
const myConstFloat = 3.14;
const myConstStringWithDoubleQuotes = "Hello, world!";
const myConstStringWithSingleQuotes = 'Hello, world!';
const myConstStringWithBackticks = `Hello, world!`;
const myConstNull = null;
const myConstUndefined = undefined;
const myConstSymbol = Symbol("myConstSymbol");
// 9. A continuación, modifica los valores de las constantes
/*
myConstBoolean = false;
myConstNumber = 100;
myConstFloat = 2.718;
myConstStringWithDoubleQuotes = "Goodbye, world!";
myConstStringWithSingleQuotes = 'Goodbye, world!';
myConstStringWithBackticks = `Goodbye, world!`;
myConstNull = {};
myConstUndefined = undefined;
myConstSymbol = Symbol("anotherConstSymbol");
*/
// 10. Comenta las líneas que produzcan algún tipo de error al ejecutarse