JavaScript 语法基础

JavaScript 是一种广泛使用的编程语言,它主要用于网页开发。以下是一些基础的 JavaScript 语法要点。

变量声明

在 JavaScript 中,有几种方式可以声明变量:

  • 使用 var 关键字
  • 使用 let 关键字
  • 使用 const 关键字
var a = 10;
let b = 20;
const c = 30;

数据类型

JavaScript 有以下几种基本数据类型:

  • number:数字
  • string:字符串
  • boolean:布尔值
  • null:空值
  • undefined:未定义
  • object:对象
let x = 5; // number
let y = "Hello"; // string
let z = true; // boolean

运算符

JavaScript 支持各种运算符,包括:

  • 算术运算符:+, -, *, /, %
  • 关系运算符:==, ===, !=, !==, <, >, <=, >=
  • 逻辑运算符:&&, ||, !
let result = 10 + 5; // 15
let result = 10 == 10; // true

函数

函数是 JavaScript 中的核心概念之一:

function greet(name) {
  return "Hello, " + name;
}

let message = greet("Alice");
console.log(message); // Hello, Alice

图片

JavaScript Logo

更多关于 JavaScript 的内容,您可以访问JavaScript 教程



JavaScript is a widely-used programming language primarily used for web development. Here are some basic points about JavaScript syntax.

### Variable Declaration

There are several ways to declare variables in JavaScript:

- Using the `var` keyword
- Using the `let` keyword
- Using the `const` keyword

```javascript
var a = 10;
let b = 20;
const c = 30;

Data Types

JavaScript has the following basic data types:

  • number: Numbers
  • string: Strings
  • boolean: Boolean values
  • null: Null
  • undefined: Undefined
  • object: Objects
let x = 5; // number
let y = "Hello"; // string
let z = true; // boolean

Operators

JavaScript supports various operators, including:

  • Arithmetic operators: +, -, *, /, %
  • Relational operators: ==, ===, !=, !==, <, >, <=, >=
  • Logical operators: &&, ||, !
let result = 10 + 5; // 15
let result = 10 == 10; // true

Functions

Functions are a core concept in JavaScript:

function greet(name) {
  return "Hello, " + name;
}

let message = greet("Alice");
console.log(message); // Hello, Alice

Image

JavaScript Logo

For more information about JavaScript, you can visit the JavaScript Tutorial.