-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathescopo_variaveis.html
More file actions
43 lines (29 loc) · 903 Bytes
/
escopo_variaveis.html
File metadata and controls
43 lines (29 loc) · 903 Bytes
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript - Escopo de Variáveis</title>
<script>
//3 escopos: global, função e o bloco
var serie = 'Friends'
//escopo de bloco
if (true) {
var serie2 = 'Game of Thrones' //hoisting(elevação) -> essa variável é elevada ao escopo global, pois o escopo de bloco está dentro do escopo global
document.write(serie)
}
document.write(serie2)
document.write('<br/ >')
//escopo de função
function x() {
var serie3 = 'The Walking Dead' //nâo é elevada, essa variável só pode ser acessada dentro da função
document.write(serie)
document.write(serie2) //escopo da função tem acesso as variáveis do escopo global
}
x()
document.write('<br />')
document.write(serie3)
</script>
</head>
<body>
</body>
</html>