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
10 Costly Database Performance Mistakes (And How To Fix Them)
andyatkinson
0
330
Python型ヒント完全ガイド 初心者でも分かる、現代的で実践的な使い方
mickey_kubo
1
110
設計やレビューに悩んでいるPHPerに贈る、クリーンなオブジェクト設計の指針たち
panda_program
6
2.1k
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
190
AI時代の『改訂新版 良いコード/悪いコードで学ぶ設計入門』 / ai-good-code-bad-code
minodriven
10
3k
Hypervel - A Coroutine Framework for Laravel Artisans
albertcht
1
120
地方に住むエンジニアの残酷な現実とキャリア論
ichimichi
5
1.5k
High-Level Programming Languages in AI Era -Human Thought and Mind-
hayat01sh1da
PRO
0
770
LT 2025-06-30: プロダクトエンジニアの役割
yamamotok
0
750
Porting a visionOS App to Android XR
akkeylab
0
460
5つのアンチパターンから学ぶLT設計
narihara
1
170
iOS 26にアップデートすると実機でのHot Reloadができない?
umigishiaoi
0
130
Featured
See All Featured
Faster Mobile Websites
deanohume
307
31k
Fireside Chat
paigeccino
37
3.5k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Why Our Code Smells
bkeepers
PRO
336
57k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Side Projects
sachag
455
42k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
820
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.4k
How to Think Like a Performance Engineer
csswizardry
25
1.7k
Become a Pro
speakerdeck
PRO
29
5.4k
Git: the NoSQL Database
bkeepers
PRO
430
65k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
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