--- id: javascript-set-logic title: "JavaScript Set Logic" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["Set logic", "union", "intersection", "difference", "symmetricDifference", "isSubsetOf", "isDisjointFrom"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "set", "set-logic"] raw_sources: ["https://www.w3schools.com/js/js_set_logic.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Set Logic]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) JavaScript 2025 added seven set-theory methods to `Set` β€” `union`, `intersection`, `difference`, `symmetricDifference` (returning new Sets) and `isSubsetOf`, `isSupersetOf`, `isDisjointFrom` (returning booleans) β€” for direct mathematical set operations. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Seven logical Set methods** were added to the Set object in JavaScript 2025. [S1] - **Combining methods return a new Set** β€” `union`, `intersection`, `difference`, `symmetricDifference`. [S1] - **Relationship methods return a boolean** β€” `isSubsetOf`, `isSupersetOf`, `isDisjointFrom`. [S1] - **Each operates on this Set and an argument Set** β€” e.g. `A.union(B)`. [S1] - **Browser support is recent** β€” Chrome/Edge 136 (Apr 2025), Firefox 129 (Aug 2024), Safari 18.2 (Dec 2024), Opera 120 (May 2025). [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Binary set operation** β€” call a method on set A passing set B: `const C = A.intersection(B);`. [S1] - **New-Set vs predicate** β€” combining ops yield a Set you store; relationship ops yield a `true`/`false` you store in `answer`. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **union()** β€” returns a new set containing the elements which are in this set, or in the argument set, or in both: [S1] ```javascript const A = new Set(['a','b','c']); const B = new Set(['b','c','d']); const C = A.union(B); ``` **intersection()** β€” returns a new set containing the elements which are in this set and in the argument set: [S1] ```javascript const A = new Set(['a','b','c']); const B = new Set(['b','c','d']); const C = A.intersection(B); ``` **difference()** β€” returns a new set containing elements which are in this set but not in the argument set: [S1] ```javascript const A = new Set(['a','b','c']); const B = new Set(['b','c','d']); const C = A.difference(B); ``` **symmetricDifference()** β€” returns a new set containing elements which are in this set or in the argument set, but not in both: [S1] ```javascript const A = new Set(['a','b','c']); const B = new Set(['b','c','d']); const C = A.symmetricDifference(B); ``` **isSubsetOf()** β€” returns `true` if all elements in this set is also elements in the argument set: [S1] ```javascript const A = new Set(['a','b','c']); const B = new Set(['b','c','d']); let answer = A.isSubsetOf(B); ``` **isSupersetOf()** β€” returns `true` if all elements in the argument set are also in this set: [S1] ```javascript const A = new Set(['a','b','c']); const B = new Set(['b','c','d']); let answer = A.isSupersetOf(B); ``` **isDisjointFrom()** β€” returns `true` if this set has no elements in common with the argument set: [S1] ```javascript const A = new Set(['a','b','c']); const B = new Set(['b','c','d']); let answer = A.isDisjointFrom(B); ``` **Browser Support** β€” JavaScript Set Logic methods are supported in modern browsers from 2024-2025: [S1] | Browser | Version | Release | |---------|---------|---------| | Chrome | 136 | Apr 2025 | | Edge | 136 | Apr 2025 | | Firefox | 129 | Aug 2024 | | Safari | 18.2 | Dec 2024 | | Opera | 120 | May 2025 | ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own snippets are the canonical applied examples β€” running each operation over two fixed Sets `A = {a,b,c}` and `B = {b,c,d}`, storing combining results in `C` and relationship results in `answer`. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Intersection of two Sets (language: JavaScript): ```javascript const C = A.intersection(B); ``` Subset predicate: ```javascript let answer = A.isSubsetOf(B); ``` ## βš–οΈ 비ꡐ 및 선택 κΈ°μ€€ (Comparison & decision criteria) Choose the method by the question being asked, per the source definitions: [S1] - Need everything from both β†’ `union()`. - Need only shared elements β†’ `intersection()`. - Need this set minus the other β†’ `difference()`. - Need elements unique to one side (the XOR) β†’ `symmetricDifference()`. - Just need a yes/no relationship β†’ `isSubsetOf()`, `isSupersetOf()`, or `isDisjointFrom()` (boolean, no new Set produced). ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) These are new additions (JavaScript 2025). Older runtimes predating the browser versions listed will not have them. No contradictions found in the source. [S1] ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Sets]], [[JavaScript Set Methods]], [[JavaScript Maps]] - **μ°Έμ‘° λ§₯락:** Referenced when performing mathematical set operations between two Sets. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Set Logic β€” https://www.w3schools.com/js/js_set_logic.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Set Logic" page (Astra wiki-curation, P-Reinforce v3.1 format).