JavaScript 简介

第 1 天:JavaScript 简介

欢迎来到 JavaScript 学习之旅的第一天!今天,我们将介绍 JavaScript 的基础知识、它在 Web 开发中的重要性以及如何开始有效地使用它。

什么是 JavaScript?

JavaScript (JS) 是一种功能强大、用途广泛的编程语言,主要用于为网站添加交互性和动态功能。它与 HTML 和 CSS 一起,是 Web 开发的核​​心技术之一。

为什么 JavaScript 至关重要

  • 使网页具有交互性(例如滑块、表格、动态内容)。
  • 允许实时更新而无需重新加载页面(AJAX)。
  • 构成 React、Angular 和 Vue 等流行框架的基础。
  • JavaScript 入门

    在浏览器中运行 JavaScript

    Chrome、Firefox 和 Edge 等现代浏览器都带有内置控制台。

  • 打开浏览器。
  • 右键单击页面上的任意位置并选择“检查”或按 F12。
  • 转到控制台选项卡。
  • 尝试输入:

    console.log("Hello, Arjun I am your Instructor!");

    您应该看到输出:“您好,Arjun,我是您的导师!”

    将 JavaScript 链接到 HTML

    要在项目中使用 JavaScript,请执行以下操作:

  • 创建一个 HTML 文件(例如,index.html)。
  • 使用链接 JavaScript 文件
  • Example:

    
    
    
        
        
        JavaScript Basics
    
    
        

    Welcome to JavaScript!

    Open the console to see the magic.

  • Create a file named script.js in the same directory and add:
  • console.log("JavaScript is connected!");

    Open `index.html` in your browser and check the console to verify the connection.

    Your First JavaScript Program

    Let’s create a simple JavaScript program:

    Example:

    // Declare a variable
    let message = "Welcome to JavaScript!";
    
    // Print the message to the console
    console.log(message);
    
    // Perform a simple calculation
    let sum = 5 + 3;
    console.log("The sum of 5 and 3 is:", sum);

    Summary of Day 1

    Today, you learned:

  • What JavaScript is and its importance in web development.
  • How to run JavaScript in the browser console.
  • How to link a JavaScript file to an HTML document.
  • Writing a basic JavaScript program.
  • Practice for Day 1

  • Create an HTML page and link a JavaScript file to it.
  • Write a program in JavaScript to: Print your name and favorite hobby. Calculate the product of two numbers.
  • Ready for Day 2? Tomorrow, we’ll dive into **variables and data types** to strengthen your understanding of JavaScript!