Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Javascript, um menino serelepe | Javascript, a serelepe guy

Javascript, um menino serelepe | Javascript, a serelepe guy

- 16º Guru Sorocaba (12/01/2019)
- Front in Santa Maria (08/06/2019)

Juliana Negreiros

June 08, 2019
Tweet

More Decks by Juliana Negreiros

Other Decks in Technology

Transcript

  1. var imprima = (valor) => { console.log(valor) if(valor > 5){

    var novoValor = valor + 1 console.log(novoValor) } console.log(novoValor) } > imprima(4) > 4 > undefined > imprima(6) > 6 > 7 > 7
  2. const imprima = (valor) => { console.log(valor) if(valor > 5){

    const novoValor = valor + 1 console.log(novoValor) } console.log(novoValor) } > imprima(4) > 4 > Uncaught ReferenceError: novoValor is not defined > imprima(6) > 6 > 7 > Uncaught ReferenceError: novoValor is not defined
  3. typeof > typeof 1 > 'number' > typeof 'ju' >

    'string' > typeof true > 'boolean' > typeof () => {} > 'function'
  4. typeof > arr[0] = 'ju' > obj.nome = 'ju' >

    obj['nome'] = 'ju' > typeof [] > 'object' > typeof {} > 'object'
  5. null vs undefined > let nome > let nome =

    null > typeof null > 'object' > typeof undefined > 'undefined' > null == undefined > true > null === undefined > false
  6. NaN > const numero = NaN > Number.isNaN(numero) > true

    > NaN == NaN > false > typeof(NaN) > 'number' JS
  7. Comparações > 0 == null > false > [] ==

    0 > true > null == undefined > true > !!undefined > false
  8. Operações > 20 + '1' > '201' > 20 -

    '1' > 19 > true - true > 0 > 20 + '1' > '201' > 'um' - 1 > 0
  9. Operações > [] + [] > '' > [] +

    {} > '[object Object]' > {} + {} > '[object Object][object Object]' > {} + [] > 0 > console.log({} + []) > '[object Object]'
  10. toString > const numeros = [1, 2, 3] > numeros.toString()

    > '1,2,3' > const idade = 24 > idade.toString() > '24'
  11. toString > const nome = new String('ju') > typeof nome

    > 'object' > nome.toString() > 'ju'
  12. toString > const nome = new String('ju') > typeof nome

    > 'object' > nome.toString() > 'ju' > const obj = {} > obj.toString() > '[object Object]'
  13. toString > const obj = { toString () { return

    'ju' } } > obj.toString() > 'ju'
  14. Resumindo > Usar === ao invés de == > Fazer

    a coerção na mão com Boolean(), Number() e String() > Não use typeof pra saber se algo é um array > Não confie em usar typeof com objetos > Bibliotecas
  15. FOQUE NO QUE DÁ PRA FAZER DE LEGAL COM A

    LINGUAGEM, NÃO NOS DEFEITOS <3