Public
Edited
Apr 23, 2023
1 star
Insert cell
Insert cell
Insert cell
{
var age = 12; // number
let name = "Zhang San"; // string
const PI = 3.1415; // number

return age * 2;
}
Insert cell
Insert cell
{
const PI = 3.1415;
PI = 1; // 常量不能被修改
}
Insert cell
Insert cell
Student = {
return {
name: "Zhang San",
age: 12
};
}
Insert cell
Student.age
Insert cell
Insert cell
Another = {
const another = Object.create(Student);
another.age = 18;

Student.salary = 100;
return another;
}
Insert cell
Another.salary
Insert cell
Insert cell
{
return {
student: {
own: Object.getOwnPropertyNames(Student),
proto: Object.getOwnPropertyNames(Student.__proto__)
},
another: {
own: Object.getOwnPropertyNames(Another),
proto: Object.getOwnPropertyNames(Another.__proto__)
}
};
}
Insert cell
Insert cell
{
return {
student: Object.keys(Student),
another: Object.keys(Another)
};
}
Insert cell
Insert cell
{
return {
student: Object.values(Student),
another: Object.values(Another)
};
}
Insert cell
Insert cell
{
return 0.1 + 0.2 === 0.3;
}
Insert cell
{
return typeof NaN;
}
Insert cell
{
return NaN === NaN;
}
Insert cell
{
return 1 == "1";
}
Insert cell
{
return 1 === "1";
}
Insert cell
{
return typeof [];
}
Insert cell
{
return [] === [];
}
Insert cell
{
return typeof ([] + []);
}
Insert cell
{
return [] == "";
}
Insert cell
{
return [] === "";
}
Insert cell
Insert cell
Insert cell
{
let numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8];

return numbers.length;
}
Insert cell
Insert cell
{
let values = [0, 1, 2];

values[0] = 3;

return values;
}
Insert cell
Insert cell
Insert cell
{
let a = [];

let sum = 0;
for (let i = 0; i < 10; i++) {
sum = sum + i;
a[i] = sum;
}

return a;
}
Insert cell
Insert cell
{
let a = [1, 1];

for (let i = 2; i < 10; i++) {
a[i] = a[i - 1] + a[i - 2];
}

return a;
}
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