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
91
0
Share
Javascript Pitfalls
Javascript Pitfalls
Breno Oliveira
May 20, 2016
More Decks by Breno Oliveira
See All by Breno Oliveira
Spring e Eureka Service Discovery
brenooliveira
0
60
Como Fazer Minha Gem e o Rails Conversarem Bem
brenooliveira
0
49
Elasticsearch - Turbinando sua aplicação PHP
brenooliveira
1
160
Elasticsearch
brenooliveira
1
120
Falando sobre testes automatizados
brenooliveira
0
91
Other Decks in Programming
See All in Programming
レガシーPHP転生 〜父がドメインエキスパートだったのでDDD+Claude Codeでチート開発します〜
panda_program
0
1.1k
「Linuxサーバー構築標準教科書」を読んでみた #ツナギメオフライン.7
akase244
0
1.4k
Claude Code × Gemini × Ebitengine ゲーム制作素人WebエンジニアがGoでゲームを作った話
webzawa
0
160
エラー処理の温故知新 / history of error handling technic
ryotanakaya
6
1.5k
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
1
170
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
110
iOS機能開発のAI環境と起きた変化
ryunakayama
0
190
Liberating Ruby's Parser from Lexer Hacks
ydah
2
2.2k
ドメインイベントでビジネスロジックを解きほぐす #phpcon_odawara
kajitack
3
800
年間50登壇、単著出版、雑誌寄稿、Podcast出演、YouTube、CM、カンファレンス主催……全部やってみたので面白さ等を比較してみよう / I’ve tried them all, so let’s compare how interesting they are.
nrslib
4
800
PHP で mp3 プレイヤーを実装しよう
m3m0r7
PRO
0
290
Road to RubyKaigi: Play Hard(ware)
makicamel
1
470
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9k
For a Future-Friendly Web
brad_frost
183
10k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.5k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
180
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
200
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
190
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
440
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
How to make the Groovebox
asonas
2
2.1k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.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