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
84
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
55
Como Fazer Minha Gem e o Rails Conversarem Bem
brenooliveira
0
44
Elasticsearch - Turbinando sua aplicação PHP
brenooliveira
1
150
Elasticsearch
brenooliveira
1
120
Falando sobre testes automatizados
brenooliveira
0
85
Other Decks in Programming
See All in Programming
Vibe Codingをせずに Clineを使っている
watany
17
5.9k
AHC 044 混合整数計画ソルバー解法
kiri8128
0
320
技術選定を未来に繋いで活用していく
sakito
3
100
地域ITコミュニティの活性化とAWSに移行してみた話
yuukis
0
220
Do Dumb Things
mitsuhiko
0
410
アーキテクトと美学 / Architecture and Aesthetics
nrslib
12
3.3k
State of Namespace
tagomoris
3
530
List とは何か? / PHPerKaigi 2025
meihei3
0
620
データベースエンジニアの仕事を楽にする。PgAssistantの紹介
nnaka2992
9
4.5k
国漢文混用体からHolloまで
minhee
1
150
サービスレベルを管理してアジャイルを加速しよう!! / slm-accelerate-agility
tomoyakitaura
1
140
自分のために作ったアプリが、グローバルに使われるまで / Indie App Development Lunch LT
pixyzehn
1
150
Featured
See All Featured
A better future with KSS
kneath
239
17k
Typedesign – Prime Four
hannesfritz
41
2.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
178
52k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
13
1.4k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
640
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
How to Ace a Technical Interview
jacobian
276
23k
Speed Design
sergeychernyshev
29
880
Building Applications with DynamoDB
mza
94
6.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
227
22k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
135
33k
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