{"id":1361,"date":"2021-04-02T19:15:42","date_gmt":"2021-04-03T02:15:42","guid":{"rendered":"https:\/\/coderpad-staging.io\/?post_type=programming-language&#038;p=1091"},"modified":"2023-04-17T03:46:39","modified_gmt":"2023-04-17T10:46:39","slug":"javascript","status":"publish","type":"programming-language","link":"https:\/\/coderpad.io\/languages\/javascript\/","title":{"rendered":"JavaScript"},"content":{"rendered":"\n<p>Use&nbsp;<a href=\"\/languages\/html-css-js\/\">HTML\/CSS\/JS<\/a>&nbsp;for React, AngularJS, Vue.js, and other Javascript frameworks.<\/p>\n\n\n\n<p>We provide a highly interactive REPL, which allows access to your runtime variables. If there were no errors, you will have a REPL with access to all of the global variables and functions defined in your script.<\/p>\n\n\n\n<p>We run NodeJS with the&nbsp;<code>--harmony<\/code>&nbsp;flag on, which gives you access to many staged new features coming to the JavaScript spec. For a complete description of which modern JavaScript features are available, check out&nbsp;<a href=\"http:\/\/node.green\/\" target=\"_blank\" rel=\"noopener\">the Node compatibility table<\/a>.Your code is also run for you in strict mode by default, which will enable features like const and let to work without configuration on your part.<\/p>\n\n\n\n<p>We also have an array of interesting npm packages available for your use:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"http:\/\/underscorejs.org\/\" target=\"_blank\" rel=\"noopener\">underscore<\/a>,&nbsp;<a href=\"https:\/\/lodash.com\/\" target=\"_blank\" rel=\"noopener\">lodash<\/a>, and&nbsp;<a href=\"https:\/\/ramdajs.com\/\" target=\"_blank\" rel=\"noopener\">ramda<\/a>&nbsp;for many useful functional helpers. Fun fact: I managed to get&nbsp;<a href=\"https:\/\/github.com\/jashkenas\/underscore\/pull\/963\" target=\"_blank\" rel=\"noopener\">_.sample<\/a>&nbsp;added to underscore. You\u2019re welcome.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.npmjs.com\/package\/chai\" target=\"_blank\" rel=\"noopener\">chai<\/a>,&nbsp;<a href=\"https:\/\/www.npmjs.com\/package\/sinon\" target=\"_blank\" rel=\"noopener\">sinon<\/a>,&nbsp;<a href=\"https:\/\/www.npmjs.com\/package\/sinon-chai\" target=\"_blank\" rel=\"noopener\">sinon-chai<\/a>, and&nbsp;<a href=\"https:\/\/www.npmjs.com\/package\/mocha\" target=\"_blank\" rel=\"noopener\">mocha<\/a>&nbsp;testing libraries.<\/li>\n<\/ul>\n\n\n\n<p>Here\u2019s a quick example of how to use&nbsp;<code>sinon<\/code>&nbsp;and&nbsp;<code>chai<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">  <span class=\"hljs-keyword\">var<\/span> chai = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">'chai'<\/span>)\n  <span class=\"hljs-keyword\">var<\/span> sinon = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">'sinon'<\/span>)\n  <span class=\"hljs-keyword\">var<\/span> sinonChai = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">'sinon-chai'<\/span>)\n\n  chai.should()\n  chai.use(sinonChai)\n\n  <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">hello<\/span>(<span class=\"hljs-params\">name, cb<\/span>) <\/span>{\n    cb(<span class=\"hljs-string\">'hello '<\/span> + name)\n  }\n\n  <span class=\"hljs-keyword\">var<\/span> cb = sinon.spy()\n  hello(<span class=\"hljs-string\">'world'<\/span>, cb)\n  cb.should.have.been.calledWith(<span class=\"hljs-string\">'this test should fail'<\/span>)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>as well as&nbsp;<code>mocha<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">  <span class=\"hljs-keyword\">var<\/span> Mocha = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">'mocha'<\/span>)\n  <span class=\"hljs-keyword\">var<\/span> assert = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">'assert'<\/span>)\n  <span class=\"hljs-keyword\">var<\/span> mocha = <span class=\"hljs-keyword\">new<\/span> Mocha()\n\n  <span class=\"hljs-comment\">\/\/ Bit of a hack, sorry!<\/span>\n  mocha.suite.emit(<span class=\"hljs-string\">'pre-require'<\/span>, <span class=\"hljs-keyword\">this<\/span>, <span class=\"hljs-string\">'solution'<\/span>, mocha)\n\n  describe(<span class=\"hljs-string\">'Test suite'<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n    it(<span class=\"hljs-string\">'should work'<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n      assert(<span class=\"hljs-literal\">true<\/span>)\n    })\n  })\n\n  mocha.run()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.npmjs.com\/package\/async\" target=\"_blank\" rel=\"noopener\">async<\/a>,&nbsp;<a href=\"https:\/\/www.npmjs.com\/package\/axios\" target=\"_blank\" rel=\"noopener\">axios<\/a>, and&nbsp;<a href=\"https:\/\/www.npmjs.com\/package\/isomorphic-fetch\" target=\"_blank\" rel=\"noopener\">isomorphic-fetch<\/a>&nbsp;for making async HTTP a little more convenient.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.npmjs.com\/package\/q\" target=\"_blank\" rel=\"noopener\">q<\/a>,&nbsp;<a href=\"https:\/\/www.npmjs.com\/package\/bluebird\" target=\"_blank\" rel=\"noopener\">bluebird<\/a>&nbsp;and&nbsp;<a href=\"https:\/\/www.npmjs.com\/package\/rxjs\" target=\"_blank\" rel=\"noopener\">rxjs<\/a>&nbsp;are promise libraries to help make managing async in&nbsp;<em>general<\/em>&nbsp;easier.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.npmjs.com\/package\/jsdom\" target=\"_blank\" rel=\"noopener\">jsdom<\/a>&nbsp;is a library for mimicking an HTML DOM within our JS environment. Useful if you want to test how candidates can manipulate elements without using our full HTML\/JS\/CSS environment.<\/li>\n<\/ul>\n","protected":false},"parent":0,"menu_order":0,"template":"","class_list":["post-1361","programming-language","type-programming-language","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/programming-language\/1361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/programming-language"}],"about":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/types\/programming-language"}],"wp:attachment":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/media?parent=1361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}