Published
Edited
Apr 30, 2020
8 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
var color = 'blue'; //color declared
color = 'black' //color reassigned
var color = 'pink' //color redeclared
return color
}
Insert cell
Insert cell
{
// var can be reassigned and redeclared
var color = 'red';
// color = 'blue';
// var color = 'gold';
return color;
}
Insert cell
{
// let can be reassigned but NOT redeclared
//uncomment each line one at a time and run, notice the error when you try to REDECLARE using let
let color = 'yellow'
// color = 'green'
// let color = 'white'
return color
}
Insert cell
{
//notice how you can't reassign nor redecalre with const?
const color = 'purple';
// color = 'violet';
// const color = 'pink';
return color
}
Insert cell
Insert cell
{
const listOfComputerComp = ['apple', 'dell'];
listOfComputerComp.push('compaq');
// listOfComputerComp = [1, 1];
// listOfComputerComp.pop();
return listOfComputerComp;
}
Insert cell
Insert cell
Insert cell
Insert cell
jsFile = {
//Global Scope
let milkyWay = 'I am globally scoped, so you can access me anywhere!';
{ //Block Scope
var earth = 'Earth';
const sun = 'Sun';
let house = 'My house';
}
//UNCOMMENT THESE ONE AT A TIME TO SEE WHAT HAPPENS (REMEMBER TO RECOMMENT THE LINE YOU UNCOMMENTED ALREADY)
// return earth;
// return milkyWay
// return house;
return sun;

}
//
Insert cell
Insert cell
Insert cell
Insert cell
{
return name;
var name = 'Beth';
}
//notice that we return name first and it name was assigned as 'undefined'

Insert cell
{
return name;
let name = 'Hanayo';
}
//let and const doesn't get referenced in the beginning of the scope, but rather just declared without being assigned to any value
Insert cell
{
return name;
let name = 'Tofe';
}

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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