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
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
500
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
9
3.2k
CloudflareのSandbox SDKを試してみた
syumai
0
990
実践AIチャットボットUI実装入門
syumai
9
4.4k
ProxyによるWindow間RPC機構の構築
syumai
3
1.6k
CloudflareのChat Agent Starter Kitで簡単!AIチャットボット構築
syumai
2
1.3k
Other Decks in Programming
See All in Programming
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
360
楽しそうなつよつよエンジニアと目が死んでる僕/A brilliant engineer having a blast, and dead-eyed me.
3l4l5
2
180
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
790
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
730
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
600
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
660
VibeCodingからAgenticWorkflowへ
starfish719
0
490
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
500
php-fpmのプロセスが枯渇した日-調査・対処・そして本当にやるべきだったこと-
shibuchaaaan
0
290
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
4
440
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
180
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
160
Featured
See All Featured
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
330
The Art of Programming - Codeland 2020
erikaheidi
57
14k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
270
Evolving SEO for Evolving Search Engines
ryanjones
0
250
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
230
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
Thoughts on Productivity
jonyablonski
76
5.3k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
66
57k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
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
ご清聴ありがとうございました!