Published
Edited
Jul 7, 2020
2 forks
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function hello(param) {
//当使用函数的时候,可以传参数进来, 我们给参数取个名字,就叫 param, 这和给变量取名是一个道理
console.log('我是 hello 函数', param); // console.log 是浏览器提供的函数, 我们可以随时调用它

/*
这是注释的另一种写法, 这样的注释可以写多行, 而 // 后面的注释只能写一行

log 函数会打印你指定的内容, 可以用逗号隔开多个要打印的内容
类似 log 这样的自带函数还有很多, 大部分你要做的事情, 都有自带函数可以使用, 那为什么还要写函数?
因为有些事情没有自带函数能做, 还有的时候, 同样的代码你需要用到n次, 但你不想写n次
*/
}
Insert cell
Insert cell
Insert cell
Insert cell
{
// 点击最右边的运行符号,就会运行本块代码, 也可以使用快捷键 {shift + 回车}
hello(); // 调用函数时不提供参数
hello(332); // 提供一个数字 332 作为参数,
hello('嘿嘿'); // 提供一个字符串作为参数
return '下面执行了刚刚编写的 hello 函数, 所以能看到 console.log 函数输出的内容';
}
Insert cell
Insert cell
{
// 这是一个 Block, 因为用花括号{}包裹起来了, 所以可以写 n 行代码
// 你能看到上面显示 undefined, 上面部分是 Block 代码执行完成后的返回结果
// 而这些注释, 就是 Block 的代码
console.log('有点饿');
// 因为这段代码 没有返回任何东西 所以上面显示 undefined(未定义)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
time = new Date(a).toLocaleString()
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