munchor's blog

By munchor, 6 years ago, In English,

Recently, the Codeforces team announced that they were adding support for problem resolution using JavaScript. I was quite glad with these news and have since started using JavaScript in every contest.

Running and testing the code locally

I use d8, the JavaScript interpreter in Google's V8 JavaScript engine. I run different test cases using redirected input and output calling d8 on my shell. If I need to quickly test any JavaScript syntax, calling d8 by itself lets me run JavaScript commands as with any interpreter (think Python).

JavaScript and IO

d8 provides IO functions such as print() (automatic newline), write() and readLine(). I prefer C's IO, but using readLine, I can simplify code a lot using split and map. For example, say I want a one-liner to read a list of space-separated integers without knowing how many numbers are on the line, then I can simply run:

var numbers = readline().split(" ").map(function(x) { return parseInt(x); });


JavaScript engines are becoming more and more efficient as companies like Mozilla and Google push the boundaries of SpiderMonkey and V8, respectively, to execute JavaScript faster. The speed of JavaScript is still not comparable to the speed of C and C++ (of course), but it is noticeably faster than most interpreted languages such as Python or Ruby and still provides us with quite a lot of syntactic sugar like these.

JavaScript is not just about the Web

A lot of people still think JavaScript is just a language browsers use, but it's a whole different beast. You can use it for all sorts of stuff and I'll definitely keep using it for Codeforces (even if just now and then).

  • Vote: I like it
  • +15
  • Vote: I do not like it

4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone please tell me if there is any downloadable version of d8. If there is, from where can I download it?

3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Great step you have define it is really helpful for all developer making a website on javascript

4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

can you please make it clear how to test js code locally using d8. i.e., installing d8 how to use it. I was not able to use readline() to get input from process.stdin. :(

4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Are there any plans to upgrade to a newer version of JavaScript? ES6 is not supported and there are issues with big numbers in the current archaic version of JavaScript.