Published
Edited
Mar 27, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
{
var number = 2;
number = 3; // This is "reassign"
var number = 4; // This is "redeclare"
return number
}
Insert cell
Insert cell
{
// VAR
var number = 2;
number = 3; // VAR can be reassigned
var number = 4; // VAR can be redeclared
return number
}
Insert cell
{
// LET
let number = 2;
number = 3; // LET can be reassigned
// let number = 4; // LET cannot be redeclared. TRY UNCOMMENTING THIS LINE
return number
}
Insert cell
{
// CONST
const number = 2;
// number = 3; // CONST cannot be reassigned. TRY UNCOMMENTING THIS LINE
// let number = 4; // CONST cannot be redeclared. TRY UNCOMMENTING THIS LINE
return number
}
Insert cell
Insert cell
{
const numbers = [1,2];
let newNumber = Math.floor(Math.random() * 10);
numbers.push(newNumber);
// numbers.pop(newNumber);
return numbers;
}
Insert cell
{
const ranking = {
Mike: 1,
Tom: 2,
Jack: 3
}
ranking.Tom = 20
return ranking.Tom
}
Insert cell
Insert cell
jsExample = {
// Global scope:
var global_one = "a global scoped variable declared by var";
let global_two = "a global scoped variable declared by let";
const global_three = "a global scoped variable declared by const";
if (4 > 3) {
// Block scope:
var block_one = "Block scoped variables created by var IS accessible outside the block"
let block_two = "Block scoped variables created by let is NOT accessible outside the block";
const block_three = "Block scoped variables created by const is NOT accessible outside the block";
}
// Function Scope:
function temperature(month) {
var normal_temp = 50;
let error = 10;
const constant = 0.5;
return normal_temp + error + constant + month
}
return global_one
// return block_two
// return block_one
// return temperature(12)
// return normal_temp
// return error
// return constant
}
Insert cell
Insert cell
Insert cell
{
var number = 1;
// let number = 1
if (true) {
var number = 3;
// let number = 3
}
return number
}
Insert cell
Insert cell
Insert cell
{
if (1 > 2) {
var impossible = 3;
// let impossible = 3;
}

impossible = 4;
return impossible
}
Insert cell
Insert cell
Insert cell
Insert cell
cellOne = 1
Insert cell
cellTwo = cellOne * 2
Insert cell
CellThree = {
let a = 0;
if (a < 1) {
a += 1; // LET can be reassigned.
}
return a
}
Insert cell
CellFour = CellThree * 3
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more