JavaScript Overview
什么 JavaScript 是, 哪里它 运行, and 为什么它 是必要 for modern web development.
你将学到
- 什么 JavaScript 是 and 哪里它 运行 (浏览器, 服务器, 边缘)
- 为什么 JavaScript 是必要 for interactive web pages
- 如何 JavaScript differs 从 Java and other languages
- role 的 JavaScript engine (V8, SpiderMonkey, JavaScriptCore)
概念讲解
什么是 JavaScript?
JavaScript is a high-level, interpreted programming language that originally ran only inside web browsers. Today it is one of the most widely used languages in the world, powering everything from interactive front-end UIs to back-end servers, mobile apps, desktop apps, and even embedded devices.
Where JavaScript Runs
- Browsers: Every modern browser (Chrome, Firefox, Safari, Edge) ships a JavaScript engine. Chrome uses V8, Firefox uses SpiderMonkey, and Safari uses JavaScriptCore.
- Servers: Node.js runs JavaScript outside the browser using the same V8 engine, letting you build back-end services, CLIs, and build tools.
- Edge & embedded: Cloudflare Workers, Deno, and Bun run JavaScript at the network edge or in lightweight runtimes.
Why JavaScript Is Essential
HTML defines structure, CSS defines appearance, and JavaScript defines behavior. Without JavaScript, a web page is static — you cannot react to clicks, validate a form, fetch new data, or animate elements. JavaScript is the only programming language all browsers understand natively, which makes it the lingua franca of the web.
JavaScript vs Java
Despite the similar name, JavaScript and Java are completely different languages designed by different companies for different purposes. Java is a statically typed, compiled language that runs on the Java Virtual Machine (JVM); JavaScript is a dynamically typed, interpreted language that runs in a JS engine. The name "JavaScript" was a marketing decision in 1995 to ride on Java's popularity.
A Brief History
JavaScript was created by Brendan Eich at Netscape in 1995 in just ten days. It was standardized under the name ECMAScript (ES). Major milestones include ES5 (2009), ES6/ES2015 (a huge leap that added let, const, arrow functions, classes, and promises), and the now-annual release cadence.
示例代码
// JavaScript runs in the browser console, Node.js, and many other runtimes.
console.log("Hello from JavaScript!");
// JavaScript can do math, string manipulation, and logic directly.
const greeting = "Welcome to CoderNewbie";
const year = new Date().getFullYear();
console.log(`${greeting} — ${year}`);
// Everything in the browser console is JavaScript.
console.log("1 + 2 =", 1 + 2);
console.log("Type of 42 is", typeof 42);
粘贴这个到 你的浏览器 console (F12 → Console) or 运行它 使用节点.js. console.log() prints 到标准输出, 哪个是 developer console in 浏览器 or terminal in 节点.js.
动手试一试
- JSON Formatter
JavaScript 对象 look 如 JSON — 练习格式化它们.
- Regex Tester
JavaScript RegExp 是 used everywhere in web code — 动手试一试 live.
常见错误
错误写法
Confusing Java 使用 JavaScript
正确做法
它们是 completely 不同 languages. JavaScript 运行 in 浏览器 and 节点.js; Java 运行 on JVM. 相似 name 是 1995 marketing trick.
错误写法
Thinking JavaScript 仅运行 in 浏览器
正确做法
节点.js, Deno, and Bun 运行 JavaScript on 服务器 and network 边缘. 相同 language powers 前面-端 and 后面-端 code.
相关资源
相关代码片段
- 数组映射 / 筛选 / Reduce
真实-世界示例的 functional 数组方法.
相关速查表
- JavaScript Cheatsheet
完整引用的 JavaScript 语法 and 常见模式.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。