寒假生活指导 11

JavaScript 基础知识点:

  1. 变量声明
    var:函数作用域,存在变量提升
    let/const:块级作用域,无变量提升,const声明常量
    命名规则:字母/_/$开头,区分大小写

  2. 数据类型
    基本类型:
    Number, String, Boolean, undefined, null, Symbol, BigInt
    引用类型:
    Object(含 Array, Function, Date 等)
    类型检测:
    typeof(检测基本类型)
    instanceof(检测对象类型)
    Array.isArray()(检测数组)

  3. 作用域与闭包
    作用域类型:全局作用域、函数作用域、块级作用域
    闭包:函数访问其词法作用域外的变量
    常见场景:模块化、回调函数、数据封装

  4. 函数基础
    声明方式:
    function fn() {} // 函数声明
    const fn = function() {} // 函数表达式
    const fn = () => {} // 箭头函数(无this绑定)
    参数传递:基本类型传值,对象类型传引用
    默认参数:function fn(a = 1) {}

  5. 对象操作
    定义对象:
    const obj = { key: "value" };
    const obj = new Object();

操作属性:
obj.key / obj["key"](访问)
delete obj.key(删除)
Object.keys(obj)(获取键列表)

  1. 数组方法
    增删元素:
    push() / pop()(尾部操作)
    unshift() / shift()(头部操作)
    迭代方法:
    forEach(), map(), filter(), reduce()

  2. 异步操作
    回调函数:setTimeout(callback, 1000)

Promise:
fetch(url)
.then(res => res.json())
.catch(err => console.error(err));
async/await:
async function getData() {
const res = await fetch(url);
return res.json();
}

  1. DOM操作
    获取元素:
    document.getElementById()
    document.querySelector()
    修改内容:
    element.textContent = "新内容"
    element.innerHTML = "加粗"
posted @ 2025-02-11 19:34  一如初见233  阅读(10)  评论(0)    收藏  举报