# str.isReservedWord

[JS](../../../..) ⟩ [primitives](../..) ⟩ [String](..) ⟩ [custom members]() ⟩ .isResevedWord

{% tabs %}
{% tab title="💈範例" %}
```javascript
// import String extensions
const _StringExt = require('./String_ext.js');

'continue'.isKeyword,       // true
'as'.isReservedWord,        // false
```
{% endtab %}

{% tab title="💾 程式" %}
* replit：[reserved words](https://replit.com/@pegasusroe/reserved-words#String_ext.js)

```javascript
// 📁 String_ext.js

const keywords = [
  'as',         'async',    'await',   'break',
  'case',       'catch',    'class',   'const',
  'continue',   'debugger', 'default', 'delete',
  'do',         'else',     'enum',    'export',
  'extends',    'false',    'finally', 'for',
  'from',       'function', 'get',     'if',
  'implements', 'import',   'in',      'instanceof',
  'interface',  'let',      'meta',    'new',
  'null',       'of',       'package', 'private',
  'protected',  'public',   'return',  'set',
  'static',     'super',    'switch',  'target',
  'this',       'throw',    'true',    'try',
  'typeof',     'var',      'void',    'while',
  'with',       'yield'
];

// reserved words
const reservedWords = [
  'await',    'break',      'case',
  'catch',    'class',      'const',
  'continue', 'debugger',   'default',
  'delete',   'do',         'else',
  'enum',     'export',     'extends',
  'false',    'finally',    'for',
  'function', 'if',         'import',
  'in',       'instanceof', 'new',
  'null',     'return',     'super',
  'switch',   'this',       'throw',
  'true',     'try',        'typeof',
  'var',      'void',       'while',
  'with',     'yield'
];

// getters for String
Object.defineProperties(String.prototype, {

    // 🔸 str.isKeyword
    isKeyword: {
        
        get() { return keywords.includes(this.valueOf()) }
        //                                    ^^^^^^^^^
        // 🧨 雷區
        // -----------------------------------------------
        // get() { return keywords.includes(this) }
        //                                  ^^^^
        // ❗ `this` will be "wrapped" in a `String` object,
        //    hence `false` is "always" returned.
        
    },

    // 🔸 str.isReservedWord
    isReservedWord: {
        
        get() { return reservedWords.includes(this.valueOf()) }
        //                                         ^^^^^^^^^
        // 🧨 雷區
        // -----------------------------------------------
        // get() { return keywords.includes(this) }
        //                                  ^^^^
        // ❗ `this` will be "wrapped" in a `String` object,
        //    hence `false` is "always" returned.
        
    },
});

// export
module.exports = {keywords, reservedWords};
```
{% endtab %}

{% tab title="⬇️ 應用" %}
* [keyword](../../../../grammar/token/keyword "mention")
* [reserved](../../../../grammar/token/keyword/reserved "mention")
{% endtab %}
{% endtabs %}
