# \`as\` keyword in switch head

**URL:** <https://es.discourse.group/t/as-keyword-in-switch-head/2454>\
**Category:** 💡 Ideas\
**Created:** [October 21, 2025, 4:08am UTC](https://es.discourse.group/t/as-keyword-in-switch-head/2454 "2025-10-21T04:08:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DiriectorDoc](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/diriectordoc/32/987_2.png) [@DiriectorDoc](https://es.discourse.group/u/DiriectorDoc)\
**Post date:** [October 21, 2025, 4:08am UTC](https://es.discourse.group/t/as-keyword-in-switch-head/2454/1 "2025-10-21T04:08:30Z")

</div>

My idea is the ability to define block-scoped baviables in the switch head.

```javascript
switch(object.with.deep.property as prop){
	default:
		use(prop)
}

```

This would work the same as creating a block variable just befor ethe switch statement.

```javascript
{
	let prop = object.with.deep.property;
	switch(prop){
		/* ... */
	}
}

```

I’m only writing this informally, just to see where this discussion goes.

---

<div class="post-metadata">

**Author:** ![bakkot](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bakkot/32/22_2.png) [@bakkot](https://es.discourse.group/u/bakkot)\
**Post date:** [October 21, 2025, 4:35am UTC](https://es.discourse.group/t/as-keyword-in-switch-head/2454/2 "2025-10-21T04:35:41Z")

</div>

There is a (somewhat dormant, but seeing activity lately) proposal for [declarations in conditionals](https://github.com/tc39/proposal-Declarations-in-Conditionals) i.e. `if (let x = whatever)`; this seems like a pretty natural extension (if it used declaration syntax rather than a new keyword). The idea has [come up in the issue tracker there](https://github.com/tc39/proposal-Declarations-in-Conditionals/issues/1#issuecomment-530773031).

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/senocular/32/642_2.png) [@senocular](https://es.discourse.group/u/senocular)\
**Post date:** [October 21, 2025, 1:03pm UTC](https://es.discourse.group/t/as-keyword-in-switch-head/2454/3 "2025-10-21T13:03:30Z")

</div>

Devin told me he was going to present declarations in conditionals at the next meeting (though I don’t see it on the agenda yet) so we’re probably going to be seeing more about that soon.

Update: It has been added to the agenda - [add Declarations in Conditionals to 2025/11 agenda by dcrousso · Pull Request #1983 · tc39/agendas · GitHub](https://github.com/tc39/agendas/pull/1983)

---

<div class="post-metadata">

**Author:** ![MaxArt](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/maxart/32/2315_2.png) [@MaxArt](https://es.discourse.group/u/MaxArt)\
**Post date:** [October 24, 2025, 10:46am UTC](https://es.discourse.group/t/as-keyword-in-switch-head/2454/4 "2025-10-24T10:46:33Z")

</div>

I don’t see this proposal as particularly handy wrt what’s available today, which adds just a little annoyance. It would also introduce a TypeScript-like syntax which might be problematic for future evolutions of the language.

OTOH, @bakkot reminded of a nice and possibly safer alternative. Maybe it could match the spirit of OP’s proposal?
