JavaScript is WEIRD

We Like JavaScript

Chris Sevilleja

@chrisoncode

scotch.io

Sarah Jorgenson

@sarahkapehe

auth0.com/blog

Who are we?

Chris Sevilleja

@chrisoncode

scotch.io

Sarah Jorgenson

@sarahkapehe

auth0.com/blog

🙌 Show of hands 🙌

What are we doing?

Unary Operators

  • + 👉 Convert to a number
  • ++ 👉 Increment
  • -- 👉 Decrement
  • ! 👉 Logical not
  • !! 👉 Convert to a boolean
  • typeof 👉 Check the type
  • ~ 👉 Inverts all bits. Returns number
  • delete 👉 Remove from array
  • void 👉 Discards a return value

let partyLevel = 7;

const newLevel = partyLevel++;

newLevel;

7


let partyLevel = 7;

partyLevel++;

partyLevel;

8


let partyLevel = 7;

partyLevel++; 




++partyLevel;

7

8



let partyLevel = '35';

+partyLevel

35




let partyLevel = 'hey im here';

+partyLevel

NaN

typeof hi


typeof null


typeof NaN


typeof /ab+c/


typeof document

undefined

object

number

object

object

typeof Infinity


typeof 'infinity'


typeof (() => 'hello')


typeof [1, 2, 3]


typeof new Array()

number

string

function

object

object

typeof new String()


typeof new Date()


typeof new Number()


typeof new Object()


typeof new Boolean()

!!!object!!!

Hoisting





console.log(typeof myVariable)

undefined



console.log(myVariable)

Uncaught ReferenceError


sayWhatup();


function sayWhatup() {
    alert('whatup')
}

alert




console.log(message);


var message = 'HEY everybody!';

undefined


var message;


console.log(message);


message = 'HEY everybody!';

undefined


sayWhatup();


const sayWhatup = () => {
    alert('whatup')
}

Uncaught ReferenceError:

sayWhatup is not defined

var double;

function double(num) {
  return (num * 2);
}

console.log(typeof double)

function

function double(num) {
  return (num * 2);
}

var double;

console.log(typeof double)

function

function double(num) {
  return (num * 2);
}

let double;

console.log(typeof double)

ERROR: Duplicate declaration "double"

Coercion

1 + "1"



'hello' + 'goodbye'



9 + '99' + 100

"11"

"hellogoodbye"

"999100"

12 / "6" === 2


12 - "6" === 6


12 * "6" === 72


12 + "6" === 18

true

true

true

false

["chris", "sarah"] + ["brian", "bella"]




["chris", "sarah"] - ["brian", "bella"]

"chris,sarahbrian,bella"

NaN

new Array(3).toString() === ",,"




',,' == ['', '', '']




',,' === ['', '', '']

true

true

false




[1, 2, 3] == [1, 2, 3]

false

k. thx. bai.

Chris Sevilleja

@chrisoncode

scotch.io

Sarah Jorgenson

@sarahkapehe

auth0.com/blog

Copy of JavaScript is Weird. I Like JavaScript

By Chris Sevilleja

Copy of JavaScript is Weird. I Like JavaScript

  • 245
Loading comments...

More from Chris Sevilleja