Skip to content

Don't use reserved words for keys ever#6

Closed
ssorallen wants to merge 1 commit intomasterfrom
never-use-reserved-words
Closed

Don't use reserved words for keys ever#6
ssorallen wants to merge 1 commit intomasterfrom
never-use-reserved-words

Conversation

@ssorallen
Copy link
Copy Markdown
Contributor

This one has bitten us in the past. default is a reserved word in JavaScript and causes exceptions when used. We shouldn't have an exception to this rule: just don't do it!

@hshoff
Copy link
Copy Markdown
Member

hshoff commented Nov 2, 2012

I'm in support of this 👍

@spikebrehm
Copy link
Copy Markdown
Collaborator

Of course, the exception is when some other service (like Wish Lists) expects an object with keys like private. In which case, just have to use quotes.

@hshoff
Copy link
Copy Markdown
Member

hshoff commented Nov 2, 2012

That also makes sense 👍

@ssorallen
Copy link
Copy Markdown
Contributor Author

@spikebrehm If your service is talking in JSON, it should respect the no-JS-keyword usage rule as well. It is JavaScript Object Notation after all.

@spikebrehm
Copy link
Copy Markdown
Collaborator

@ssorallen unfortunately that's not generally true. Plus, JSON keys have to be quoted in the first place to be valid.

@reissbaker
Copy link
Copy Markdown
Contributor

I like the idea that we should stay away from using reserved words if possible. Maybe the guideline should be that if you're creating an object in JS that will be consumed by other JS, it shouldn't use reserved words? And if it's being created elsewhere and you can't control it, or you need to send it somewhere that unfortunately expects reserved words, then quote it like @spikebrehm and originally @h4rry propose.

@hshoff hshoff closed this in 6220506 Nov 2, 2012
@ssorallen
Copy link
Copy Markdown
Contributor Author

@spikebrehm Aha, good point about quoting keys in JSON.

You have to quote uses of keywords as keys though, it's not an option or a style preference; it's a syntax error. The style guide should still say, "Don't use keywords as keys."

@hshoff hshoff reopened this Nov 2, 2012
@hshoff hshoff closed this in b714fe8 Nov 2, 2012
@hshoff hshoff deleted the never-use-reserved-words branch August 8, 2014 06:43
mattgperry pushed a commit to drivetribe/javascript that referenced this pull request Aug 22, 2017
Scrollable container horizontal & vertical + some input refactoring
reiscigit pushed a commit to reiscigit/javascript that referenced this pull request Oct 31, 2018
WithSoull added a commit to WithSoull/js-for-trpp that referenced this pull request Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants