Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Javascript Pitfalls
Search
Breno Oliveira
May 20, 2016
Programming
0
87
Javascript Pitfalls
Javascript Pitfalls
Breno Oliveira
May 20, 2016
Tweet
Share
More Decks by Breno Oliveira
See All by Breno Oliveira
Spring e Eureka Service Discovery
brenooliveira
0
57
Como Fazer Minha Gem e o Rails Conversarem Bem
brenooliveira
0
45
Elasticsearch - Turbinando sua aplicação PHP
brenooliveira
1
150
Elasticsearch
brenooliveira
1
120
Falando sobre testes automatizados
brenooliveira
0
87
Other Decks in Programming
See All in Programming
Tool Catalog Agent for Bedrock AgentCore Gateway
licux
7
2.5k
Laravel Boost 超入門
fire_arlo
3
220
print("Hello, World")
eddie
2
530
FindyにおけるTakumi活用と脆弱性管理のこれから
rvirus0817
0
540
Oracle Database Technology Night 92 Database Connection control FAN-AC
oracle4engineer
PRO
1
470
Navigation 2 を 3 に移行する(予定)ためにやったこと
yokomii
0
340
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
420
Improving my own Ruby thereafter
sisshiki1969
1
160
AI Agents: How Do They Work and How to Build Them @ Shift 2025
slobodan
0
100
1から理解するWeb Push
dora1998
7
1.9k
テストコードはもう書かない:JetBrains AI Assistantに委ねる非同期処理のテスト自動設計・生成
makun
0
530
Kiroで始めるAI-DLC
kaonash
2
620
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
How to Think Like a Performance Engineer
csswizardry
26
1.9k
Into the Great Unknown - MozCon
thekraken
40
2k
Java REST API Framework Comparison - PWX 2021
mraible
33
8.8k
Gamification - CAS2011
davidbonilla
81
5.4k
Raft: Consensus for Rubyists
vanstee
140
7.1k
Rails Girls Zürich Keynote
gr2m
95
14k
Speed Design
sergeychernyshev
32
1.1k
Agile that works and the tools we love
rasmusluckow
330
21k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.1k
Navigating Team Friction
lara
189
15k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
580
Transcript
JAVASCRIPT Pitfalls
Why?
None
Escopos • Global or FuckingScope • Functions • IIFE (Immediately
Invoked Function Expression)
Global var chauehGlobal = "Chaue Ferradura"
Local var chauehGlobal = "Chaueh Ferradura"; function scope1() { var
chauehLocal = "Chaueh é Legal"; } scope1(); console.log(chauehLocal); //Arrrggg ... Reference Error
var chauehGlobal = "Chaueh Ferradura"; function scope1() { var chauehLocal
= "Chaueh é Legal"; function scope2() { var chauehLocal = "Chaueh é Chato"; console.log(chauehLocal); // é Chato } console.log(chauehLocal); // é legal }
IIFE (function(){ var local = "Chaueh é Fofo"; })(); console.log(local);
// Reference Error
javascript hoisting
– Chaueh Ferradura “JavaScript Hoisting é o comportamento default de
mover declarações a o top.”
hoisting(); // Nooooooooooooooooo function chamaChaueh() { console.log("Nooooooooooooooooo") }
function chamaChaueh() { console.log("Nooooooooooooooooo") } hoisting(); // Nooooooooooooooooo
console.log(ops); // ??? (Gui? Gabi? Wil? Alguém arrisca?) var ops
= "Chama Chaueh";
Fuck vou embora
Declare suas variáveis no começo
ops(); var ops = function(){ console.log("Chaueh é lindo"); }; Chaueh:
Tá de sacanagem BrenoPHP? Você já mostrou que isso funciona. BrenoPHP: Mostrei Chaueh? Tem certeza? Acho que não
Objetos por referência
var pessoa = { idade: 20 } var chaueh =
pessoa; chaueh.idade = 24; console.log(pessoa.idade); // 24
var pessoa = { idade: 20 } var chaueh =
Object.create(pessoa); chaueh.idade = 24; console.log(pessoa.idade); // 20 object.create
.has Own Property
var chaueh = { nome: "Chaueh Ferradura", idade: 24, sexo:
"M" } chaueh.hasOwnProperty("nome"); // true chaueh.hasOwnProperty("religiao"); // false
== ≠ ===
("0" == 0) // true ("0" === 0) // false
parseint do demo….
parseInt("08"); // 0 parseInt("08", 10); // 8
String replace
var texto = "Chaueh Ferradura era um cara legal"; texto.replace(/
/, "_"); //Chaueh_Ferradura era um cara legal texto.replace(/ /g, "_"); // Chaueh_Ferradura_era_um_cara_legal
obrigado