Files
chunyu_project/media/learn/courses/13/chapters/55.md
T
2026-08-05 23:59:15 +08:00

47 lines
865 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# JavaScript 基础语法
## 学习目标
- 了解 JavaScript 的作用
- 掌握变量和数据类型
- 学会函数定义
## JavaScript 简介
JavaScript 是一种轻量级编程语言,用于网页交互开发。
## 变量声明
```javascript
let name = "小明"; // 可变变量
const PI = 3.14159; // 常量
// var 已不推荐使用
```
## 数据类型
```javascript
let str = "Hello"; // 字符串
let num = 42; // 数字
let bool = true; // 布尔
let arr = [1, 2, 3]; // 数组
let obj = { name: "Tom" }; // 对象
```
## 函数定义
```javascript
// 函数声明
function greet(name) {
return `你好,${name}!`;
}
// 箭头函数
const add = (a, b) => a + b;
```
## 动手练习
1. 声明不同类型的变量
2. 编写计算两数之和的函数
3. 使用箭头函数处理数组