Published
Edited
Jul 4, 2018
1 star
Insert cell
Insert cell
Insert cell
Insert cell
1 == '1'
Insert cell
0 == false
Insert cell
false == [0]
Insert cell
Insert cell
Insert cell
Insert cell
1 === '1'
Insert cell
1 === 1
Insert cell
'1' === '1'
Insert cell
false === 0
Insert cell
Insert cell
{
const arr1 = [1, 2, 3]
const arr2 = [1, 2, 3]

return arr1 === arr2
}
Insert cell
{
const arr1 = [1, 2, 3]
const arr2 = arr1

return arr1 === arr2
}
Insert cell
Insert cell
0 > 1
Insert cell
0 < 1
Insert cell
1 >= 1
Insert cell
1 <= 1
Insert cell
Insert cell
Insert cell
0 || 1
Insert cell
1 || 0
Insert cell
345 || 12345
Insert cell
0 || false || 1 || 100 | ''
Insert cell
{
const a = 1
const b = 0

return a || b
}
Insert cell
{
// checkout browser console
// return0 will not be executed
const return1 = () => {
console.log('return1 executed')
return 1
}
const return0 = () => {
console.log('return0 executed')
return 0
}

return return1() || return0()
}
Insert cell
Insert cell
{
let data = null // this will be downloaded from some database and will be an array
return data[0] // we want to acces the first data from database but we catn! the data isnt there yet!
}
Insert cell
{
let data = null // this will be downloaded from some database and will be an array
return data && data[0] // we want to acces the first data from database but we catn! the data isnt there yet!
}
Insert cell
{
let data = ['Ola'] // the data arrived
return data && data[0]
}
Insert cell
{
let data = [1, 'Ola'] // the data arrived
return data && data[0]
}
Insert cell
Insert cell
{
const returnX = x => x

return returnX('Cześć!')
}
Insert cell
{
const returnX = x => x

return returnX()
}
Insert cell
{
const returnX = x => x || 'Nie podałeś żandej wartośći!'

return returnX()
}
Insert cell
{
const returnX = x => x || 'Nie podałeś żandej wartośći!'

return returnX(0)
}
Insert cell
{
const returnX = x => x || 'Nie podałeś żandej wartośći!'

return returnX('')
}
Insert cell
Insert cell
{
const x = 'asdf'
if(x === 1){
return 1
}else if(x === '1'){
return 2
}else if(x === 2){
return x
}else{
return 0
}
}
Insert cell
Insert cell
{
const add = (a, b) => {
if(typeof a !== 'number' || typeof b !== 'number' ){
throw new Error('Not all args are numbers')
}

return a + b
}

return add(1,2)

}
Insert cell
Insert cell
{
const add = (a, b) => {
if(typeof a !== 'number' || typeof b !== 'number' ){
throw new Error('Not all args are numbers')
}

return a + b
}

return add('Ala',3)

}
Insert cell
Insert cell
1 === 1 ? 'Jeden jest jeden' : 'Jeden NIE jest jeden!'
Insert cell
1 !== 1 ? 'Jeden jest jeden' : 'Jeden NIE jest jeden!'
Insert cell
Insert cell
5 > 0 ? 'Ala' + ' ' + 'ma kota!' : 'Ala nie ma kota'
Insert cell
Insert cell
0 < 3 ? 'Zero mnijesze od 3!'
Insert cell
Insert cell
{
const result = 5 > 0 ? 'Jest większe od zera ' : 'Jest mniejsze od zera'
return result
}
Insert cell
{
const x = 7
const result = x > 0 ? 'Jest większe od zera ' : 'Jest mniejsze od zera'
return result
}
Insert cell
Insert cell
{
const returnX = x => x !== undefined ? x : 'Nie podałeś żandej wartośći!'
return returnX(0)
}
Insert cell
{
const returnX = x => x !== undefined || 'Nie podałeś żandej wartośći!'
return returnX(1234567)
}
Insert cell
Insert cell
{
const x = 20
const y = 11
return (
x > 10 ?
y > 10 ?
'Obie są większe'
:
'X większy Y nie jest'
:
y > 10 ?
'X nie jest Y jest'
:
'Oba są mniejsze'
)
}
Insert cell
Insert cell
{
const checkIfTheyAreGreaterThan10 = (x, y) => ( // () are NOT necessary
x > 10 ?
y > 10 ?
'Obie są większe'
:
'X większy Y nie jest'
:
y > 10 ?
'X nie jest Y jest'
:
'Oba są mniejsze'
)
return checkIfTheyAreGreaterThan10(20, 11)
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more