ByteNote LogoByteNote

Navigation

  • Blog
  • 工具

    © 2025 ByteNote. All rights reserved.

    JS 中括号取值的undefined 判断

    Dec 23, 20222 min read
    const arr = [];
    
    // ⛔️ Cannot read properties of undefined (reading 'name')
    console.log(arr[0].name); // ❌ Bad
    
    console.log(arr[0]?.name); // ✅ Good
    
    console.log(arr[0] && arr[0].name); // ✅ Good
    

    相关文章

    Puppeteer 等待元素渲染

    Puppeteer中可通过page.waitForSelector()、page.waitFor()或page.waitForFunction()方法等待元素渲染,根据需求选择合适的方法。

    Spring Cloud nacos的几个概念

    Spring Cloud nacos中的命名空间用于环境隔离,配置分组用于服务归类,配置集对应单个配置文件。

    为什么在HTML中插入图片时要添加alt属性?——让网页更有吸引力,同时符合SEO的要求

    在HTML中插入图片时添加alt属性是为了提高网页的可访问性和搜索引擎优化,确保图片无法显示时用户能获得信息,并帮助搜索引擎识别图片内容。

    Flutter 在屏幕上进行水平拖动时执行“返回”操

    在Flutter中,通过使用GestureDetector和onHorizontalDragEnd回调,可以实现在水平拖动结束时,如果拖动速度超过设定的阈值(例如500像素/秒),则执行返回操作。

    Swift String类型和Character类型 和区别和示范

    Swift中的String类型表示有序字符序列,而Character类型表示单个Unicode字符,可通过索引访问字符串中的字符。