Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
知られているようで知られていない JavaScriptの仕様 4選
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
syumai
November 14, 2025
Programming
1.3k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
知られているようで知られていない JavaScriptの仕様 4選
syumai
November 14, 2025
More Decks by syumai
See All by syumai
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.8k
Oxlintのカスタムルールの現況
syumai
6
1.3k
Oxlintはいかにしてtsgolintのlint ruleを呼び出しているのか
syumai
2
1.4k
『[入門] Cloudflare Workers』本はなぜ誕生したのか
syumai
0
480
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
9
3.2k
CloudflareのSandbox SDKを試してみた
syumai
0
960
実践AIチャットボットUI実装入門
syumai
9
4.3k
ProxyによるWindow間RPC機構の構築
syumai
3
1.5k
CloudflareのChat Agent Starter Kitで簡単!AIチャットボット構築
syumai
2
1.3k
Other Decks in Programming
See All in Programming
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
650
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.6k
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
210
OpenSpecのproposalにbrainstormingを持たせてみた
tigertora7571
1
200
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
200
torikago - Ruby::Boxで照らすモジュラモノリスの実行境界
se4weed
1
330
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
1
120
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
410
Android CLI
fornewid
0
210
テーブルをDELETEした
yuzneri
0
130
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
200
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
470
Featured
See All Featured
RailsConf 2023
tenderlove
30
1.5k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
240
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
890
30 Presentation Tips
portentint
PRO
1
360
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
330
The Curious Case for Waylosing
cassininazir
1
450
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
660
It's Worth the Effort
3n
188
29k
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
67
56k
Transcript
知られているようで知られていない JavaScriptの仕様 4選 syumai YACP::Fukuoka *S Tech Talks (2025/11/15)
自己紹介 syumai ECMAScript 仕様輪読会 / Asakusa.go 主催 Software Design 2023年12月号から2025年2月号まで
Cloudflare Workersの連載をしました Twitter (現𝕏): @__syumai Website: https://syum.ai
カンマ演算子
カンマ演算子 , の前後に式を受け取り、後ろの式の値を演算結果とする演算子 console.log((1, 2)); // 2 console.log(((1, 2), 3));
// 3 console.log((1, (2, 3), 4)); // 4
カンマ演算子 ある変数への操作を行った直後にその値を返したい時などに使える 大体の場合は文を分ければいいので、ほぼ出番がない const f = (a) => { let
x = 0; return (x += a, x); // 変数を操作した直後に返却 }
カンマ演算子 2重配列を操作するfor文を1本で書きたい時とかに使えるらしい // 例 for (let i = 0, j
= 9; i <= 9; i++, j--) { console.log(`a[${i}][${j}] = ${a[i][j]}`); } for ( // ここは普通の変数宣言 let i = 0, j = 9; i <= 9; // ここがカンマ演算子 i++, j-- ) { console.log(`a[${i}][${j}] = ${a[i][j]}`); } https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Comma _operator#for_ループでのカンマ演算子の使用
カンマ演算子 関数オブジェクトにnameを持たせたくない時にも使える カンマ演算子を使えば、即時実行関数を使わなくていい const f1 = () => {}; //
宣言時に勝手に関数のnameに "f1" が設定される const f2 = (0, () => {}); // 式として評価してから代入しているので設定されない const f3 = (() => {})(); // 即時実行関数で評価してから代入しているので同様 console.log( f1.name, // "f1" f2.name, // "" f3.name, // "" );
direct eval / indirect eval
direct eval / indirect eval JavaScriptの世界には、2つの種類のevalがある direct eval indirect eval
これらの違いを知っていますか? function f() { let a = 0; eval("a = 1;"); // direct eval const _eval = eval; _eval("a = 2;"); // indirect eval }
direct eval / indirect eval direct evalは今のスコープを、indirect evalはグローバルスコープを操作する function f()
{ let a = 0; eval("a = 1;"); // direct eval const _eval = eval; _eval("a = 2;"); // indirect eval console.log(a); // 1 console.log(globalThis.a); // 2 }
indirect evalの入手方法 indirect evalは、 eval を一度式として評価することで入手できる カンマ演算子、optional chainなどが使える function f()
{ // いずれも indirect eval (0, eval)("a = 1;"); eval?.("b = 1;"); }
indirect eval、いつ使うのか? (そもそもユーザーが記述したコードの実行にevalは使うべきじゃない前提 で、)eval呼び出しに渡されるコードから、関数スコープの変数を見せたくない 時に使える!
Directive Prologue
この関数はstrict mode扱いになる (function() { "use strict"; with ({}) {} //
strict modeでは使えない })();
次の関数はstrict mode扱いになるか? (function() { "use not strict"; "use strict"; with
({}) {} // ? })();
答え: strict mode扱いになる
strict mode扱いになる (function() { "use not strict"; "use strict"; //
ちゃんとここのディレクティブが効く! with ({}) {} })();
Directive Prologuesの定義 Directive Prologuesは、関数、スクリプト、モジュールの冒頭に続く最長の文字列 リテラルトークンの列でしかない その途中にどんな文字列が含まれたっていい https://tc39.es/ecma262/multipage/ecmascript-language-source-code.html#sec- directive-prologues-and-the-use-strict-directive
有効なDirective Prologuesの例 (function() { "あいうえお"; 'abcde' // 明示的にセミコロンを打ったら、1行に書いてもOK "use hoge"
// セミコロンを書かなくても、自動セミコロン挿入されるのでOK "" // 空文字もOK '' // シングルクォートもOK "use strict" // これが効く! 'use fuga' // 後ろに続いててもOK with ({}) {} // strict modeなのでwith文は使えない })();
無効なDirective Prologuesの例 ディレクティブの間に文字列以外のトークンがあると、「連続した文字列リテラ ルトークン」であるという条件が満たされない (function() { "use not strict"; 1;
"use strict"; with ({}) {} // strict modeではないので、with文が使える })();
無効なDirective Prologuesの例 ` はテンプレートリテラルであって、文字列リテラルではないので、Directive Prologuesになれない (function() { `use strict`; with
({}) {} // strict modeではないので、with文が使える })();
undefined扱いのObject
typeof document.all が undefined なのに document.all === undefined が false
!?
https://developer.mozilla.org/ja/docs/Web/API/Document/all
ECMAScriptのObjectの仕様上で、 document dot all の専用の内部フィールド、 [[IsHTMLDDA]] が定義されている https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web- browsers.html#sec-IsHTMLDDA-internal-slot
typeof に、Objectに [[IsHTMLDDA]] フィールドがあるときに "undefined" という 文字列を返すオプショナルな仕様がある https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec- typeof-operator
jkr_2255さんの記事 https://qiita.com/jkr_2255/items/f9b7218d7a2b54424c12
ご清聴ありがとうございました!