There are no sample codes for this code specifically, but if you want to change this Arduino code to Javascript then the best approach would be to use the MRAA API for Javascript. http://iotdk.intel.com/docs/master/mraa/node/ . There you can see the functions you can use, so based on the Arduino functions, look for the appropriate Javascript function and begin building your code from there.