# Use keyword as identifier

**URL:** <https://es.discourse.group/t/use-keyword-as-identifier/1202>\
**Category:** 💡 Ideas\
**Created:** [February 14, 2022, 2:45pm UTC](https://es.discourse.group/t/use-keyword-as-identifier/1202 "2022-02-14T14:45:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klaider](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/klaider/32/1447_2.png) [@Klaider](https://es.discourse.group/u/Klaider)\
**Post date:** [February 14, 2022, 2:45pm UTC](https://es.discourse.group/t/use-keyword-as-identifier/1202/1 "2022-02-14T14:45:32Z")

</div>

I propose a way of writting identifier tokens, preventing them as being keyword tokens. Useful for lexical references, function parameters and so on, where string literals cannot be used. I suggest one of following syntaxes:

- `'for'i` (string literal treated as identifier)
- `\i:for` (backslash)
- `\r:for` (backslash)
- `\#for` (backslash)

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [February 14, 2022, 2:53pm UTC](https://es.discourse.group/t/use-keyword-as-identifier/1202/2 "2022-02-14T14:53:07Z")

</div>

I've adopted a convention from Python's coding standard in my own code to get around these issues. Python recommends you place a trailing underscore on variable names that are otherwise reserved by python, or that would otherwise shadow a global Python function. So, in JavaScript I'll write code like this:

```javascript
function getId(for_) {
  // ...
}

```

And, really, having a trailing underscore isn't that different from having a variable that you always have to refer to with `\#for` syntax, in many cases, the `\#` sort of just becomes part of its name, since that's the only possible way to refer to it.

---

<div class="post-metadata">

**Author:** ![Klaider](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/klaider/32/1447_2.png) [@Klaider](https://es.discourse.group/u/Klaider)\
**Post date:** [February 14, 2022, 2:57pm UTC](https://es.discourse.group/t/use-keyword-as-identifier/1202/3 "2022-02-14T14:57:01Z")

</div>

Does not sound a bad convention. The advantage of escaping though is generating type docs without underscore included.

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [February 14, 2022, 4:55pm UTC](https://es.discourse.group/t/use-keyword-as-identifier/1202/4 "2022-02-14T16:55:09Z")

</div>

Yeah, that's a good point.

Though, I could see editors choosing to include the escape in the type-doc strings anyways, because a function signature might look a little confusing if the parameters were unescaped.

For example, this looks a bit odd.

```javascript
function doThing(return: string): void

```

So, they might choose to render it like this anyways:

```javascript
function doThing(\#return: string): void

```

At which point, we're once again not doing anything better than a trailing underscore:

```javascript
function doThing(return_: string): void

```

In some cases, they might even be forced to render the `\#`, for example, if you named your parameter `\#this`, they have no choice but to render it as `function doThing(\#this: Thing): OtherThing`, because an unescaped `this` commonly means something else - it means it expects you to .call() the function with a specific this parameter of a specific type.
