41
5
As of ECMAScript 2015, JavaScript has 33 reserved keywords, such as break
, const
and new
, as well as 10 future reserved keywords, such as let
and await
.
Your task is to chain together the largest number of consecutive1 distinct reserved keywords2 while writing functional JavaScript code3.
- Consecutive reserved keywords - reserved keywords that are separated only by whitespace and/or parentheses and/or curly braces.
- Reserved keywords - any reserved or future reserved keywords as of ECMAScript 2015. Reserved keywords from older standards are excluded, a full list of allowed keywords is given below.
- Functional code - your code should run (state your runtime, if necessary), eventually halt, and not throw any runtime errors.
If your code needs a specific runtime, the used reserved keywords must not be no-ops in the given environment.
List of reserved keywords
await
break
case
catch
class
const
continue
debugger
default
delete
do
else
enum
export
extends
finally
for
function
if
implements
import
in
instanceof
interface
let
new
package
private
protected
public
return
static
super
switch
this
throw
try
typeof
var
void
while
with
yield
Scoring & examples
Your score will be equal to the largest number of consecutive distinct reserved keywords.
In the case of equal scores, shortest source code in bytes wins. Commented sections and strings don't count towards reserved keywords, but count towards byte count.
// score: 3
if (true) 0; else throw function() {}
^------------------^
// score: 2
let foo = typeof typeof void typeof void 0;
^---------^
// score: 0
/* typeof default debugger */
// score: 0, doesn't halt or debugger is no-op, depending on the environment
debugger;
Standard loopholes apply.
Sandbox discussion, for those who are interested. – Nit – 2018-04-03T23:07:03.610
I feel like this might be more interesting if you did not allow parentheses between the keywords. – Post Rock Garf Hunter – 2018-04-03T23:56:09.003
Is newline allowed? – l4m2 – 2018-04-04T02:54:38.780
@l4m2 Yes, it's whitespace. – Nit – 2018-04-04T07:13:29.383
Now that 43-score solution exist... – l4m2 – 2018-04-04T09:40:11.563
1@l4m2 The same 43-point solution is possible without newlines as well so perhaps I simply don't understand the point you're trying to make? – Nit – 2018-04-04T09:59:01.333
In the case of equal scores, shortest source code in bytes wins.
The common solution uses 4 extra chars for each word but sometimes it can do better – l4m2 – 2018-04-04T10:00:51.627Let us continue this discussion in chat.
– l4m2 – 2018-04-04T10:00:53.593@msh210 Thanks, I didn't know tags are used like that on PCG, updated. – Nit – 2018-04-05T07:57:55.453