search
HomeWeb Front-endJS TutorialJavascript is HARD (with ESadness)

Javascript is HARD (with ESadness)

長文になりますが、もう一度言わせてください。
JAVASCRIPT は難しいです。最後に会ったとき、私は Javascript の世界に足を踏み入れていました。目を輝かせ、希望に満ちたプログラマーが野生のジャングルに足を踏み入れ、「これはどれほど難しいことでしょう?」と言いました。私はどれほど間違っていたでしょうか??。ますます難しくなりましたが、私は(かろうじて)生き残っています。これが私の旅についての少し混沌とした物語です。

変数: 狂気の始まり
変数は値を保持するコンテナであり、データを保存または操作する場所です。つまり、なぜ var、let、const という 3 つの方法で作成できるのでしょうか?なぜ? ES6 では笑います
var: var は緩い大砲だと彼らは言いました。運任せのゲームをしているようなもの。近づかないでください。
let: 変化する可能性のある変数に最適です。管理が容易になります。
Const: 値は同じままです。不動の。ああ、const は値を変更できないという意味ではなく、値を再割り当てできないという意味です。
注: ECMAScript 2015 または ES6 は、JavaScript の 2 番目のメジャー リビジョンです。
ああ、文字列連結、Hello テンプレート リテラルに別れを告げました。テンプレート リテラルを使用する バッククォートを使用し、${} を使用して変数を簡単に埋め込むことができるようになりました。ここで作業は少し楽になりましたが、バッククォートと引用符をいつ使用するべきか判断できませんか?またまた心を揺さぶられる人です。

// Good old concat
const message = "Hi, " + name + ". You are " + age + " years old.";
// Template literal
const message = `Hi, ${name}! You are ${age} years old.`;

機能: 別名ミスター再利用性、ミスター保守性...
関数は、タスクを実行する一連のステートメントです。関数キーワード、関数名、パラメータの有無にかかわらず、中括弧内の JS ステートメントで構成されます。

function greet() {
  console.log("Hello, fellow strugglers?!");
}

最初は単純そうに思えました。ロジックをカプセル化し、それを呼び出し (呼び出しと言います)、ドーン!あなたはコーディング中です。
するとES6は「これはアロー関数です、使ってください」と言いました。アロー関数は単純そうに見えますよね?関数を記述するための簡単な方法です。構文を理解するのに時間がかかりました。

const greet = () => {
   console.log("Hello, fellow strugglers?!");
}

ループ: 無限と踊る。
苦しみにはさまざまな方法があります。ループでは、コードのブロックを何度も実行できます。同じコードを毎回異なる値で何度も実行する場合に便利です。それらはたくさんあります:
1. While Loop: は、条件が true である限りループし続けます。悪。私はそのいとこである do-while について話しているのではありません。
2. for ループ: 懐かしい for ループです。信頼できる for ループ。とてもおなじみです。非常に安全であり、変数をインクリメントするのを忘れた場合に無限ループが発生する可能性が十分にあります。
3. forEach: これは、for ループのクールで流行に敏感な従兄弟のようなものです。カウンターも必要ないし、無限に連れて行ってくれるわけでもない。私の男。
4. & 5. for..in と for..of: 1 つはオブジェクトのループに最適で、もう 1 つは配列の反復に適しています。私はそれらを混ぜ続け、痛みを通して学びます。まだ勉強中です。

//for loop
for (let i = 0; i  console.log(num));

配列: 探索を続けるリスト
Array は非常に有望なスタートを切りました。簡単なアイテムのリスト。物を押し込んだり、物を引き出したりします。簡単ですよね?

let shoppingList = ["apples", "bananas", "chocolate"];
shoppingList.push("ice cream");
console.log(shoppingList); // ['apples', 'bananas', 'chocolate', 'ice cream']

フィルター、マップ、検索と残りの配列メソッド群を入力します。それ以来、私の脳は以前と変わっていません。
filter() メソッドは、関数によって提供されるテストに合格する要素で満たされた新しい配列を作成します。
find() メソッドは、テストに合格した最初の要素の値を返します。配列メソッドはたくさんあります。それぞれについてドキュメントが必要ですか?、つまり、長さ、スプライス、スライス、結合、ポップ、プッシュ、シフト解除、シフト、マップなどがあります。ここでやめましょう。

let numbers = [1, 2, 3, 4, 5];
let evenNumbers = numbers.filter(num => num % 2 === 0);
console.log(evenNumbers); // [2, 4]

オブジェクト: 配列の紛らわしいいとこ
次にオブジェクトが登場しました。オブジェクトは配列に似ていますが、キーと値を持ちます。 「よし、これなら大丈夫だ」と思いました。しかしその後、JavaScript がメソッドを追加し、突然オブジェクトが独自に処理を行うようになりました。そしてオブジェクトの配列が方程式に加わりました。プロパティへのアクセスには、ドット表記または括弧表記を使用しています。 で始めないでください。これ

//Without method
let shoppingCart = {
  apples: 3,
  bananas: 2,
  chocolate: 1
};
// with method
let cart = {
  items: ["apple", "banana"],
  addItem(item) {
    this.items.push(item);
  }
};
cart.addItem("chocolate");
console.log(cart.items); // ['apple', 'banana', 'chocolate']

DOM Manipulation: Where the Real Struggles Began
Once I felt confident with arrays and objects, I thought, “Time to manipulate the DOM! I’m practically a web developer now!” You know nothing, Ygritte famously said.
This should be easy, i said again. Just grab an element and change it. If its an ID, getElementbyId is there for me. A class getElementsbyClassName is also there or queryselector and the one with All its brother.
And then there’s this whole addEventListener business. Sure, it works, but sometimes, events seem to fire off like they have a mind of their own.
Then i tried creating a shopping cart. Took me days and lots of SOS signal to my learned colleagues. Here I'm appendChild, removingChild, creatingElements, grabbing elements, setting attributes, styling, calling functions upon functions.
Then boldly added a mock database; me and array manipulation again. I'm accessing, I'm pushing, I'm finding, I'm tired (gets up again).

Imports and Exports: Boldly sharing the Madness??
At some point, I had written so much JavaScript that I needed to modularize my code. Enter import and export.

Copy code
// module.js
export function greet() {
  console.log("Hello from the module!");
}

// main.js
import { greet } from './module.js';
greet();

I thought breaking my code into smaller pieces would make it easier. Little did I know, I would end up importing a mountain of confusion.

Now I'm about to start Object-Oriented Programming (OOP) sounds fancy, But let me enjoy my weekend first before i get lost again.
Thanks for staying till the end. The goal still remains 1% better everyday. #ES6 #CodingStruggles #WebDevelopment #JavaScriptMadness #ProgrammingHumor #LearnToCode

The above is the detailed content of Javascript is HARD (with ESadness). For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Relationship Between JavaScript, C  , and BrowsersThe Relationship Between JavaScript, C , and BrowsersMay 01, 2025 am 12:06 AM

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js Streams with TypeScriptNode.js Streams with TypeScriptApr 30, 2025 am 08:22 AM

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

Python vs. JavaScript: Performance and Efficiency ConsiderationsPython vs. JavaScript: Performance and Efficiency ConsiderationsApr 30, 2025 am 12:08 AM

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

The Origins of JavaScript: Exploring Its Implementation LanguageThe Origins of JavaScript: Exploring Its Implementation LanguageApr 29, 2025 am 12:51 AM

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

Behind the Scenes: What Language Powers JavaScript?Behind the Scenes: What Language Powers JavaScript?Apr 28, 2025 am 12:01 AM

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The Future of Python and JavaScript: Trends and PredictionsThe Future of Python and JavaScript: Trends and PredictionsApr 27, 2025 am 12:21 AM

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Python vs. JavaScript: Development Environments and ToolsPython vs. JavaScript: Development Environments and ToolsApr 26, 2025 am 12:09 AM

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Is JavaScript Written in C? Examining the EvidenceIs JavaScript Written in C? Examining the EvidenceApr 25, 2025 am 12:15 AM

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function