{"id":22505346,"url":"https://github.com/azer/javascript-guide","last_synced_at":"2025-04-14T10:12:18.568Z","repository":{"id":8316785,"uuid":"9865418","full_name":"azer/javascript-guide","owner":"azer","description":"Azer's JavaScript Guide","archived":false,"fork":false,"pushed_at":"2014-03-27T22:10:38.000Z","size":224,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T23:25:51.964Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-05T07:26:00.000Z","updated_at":"2024-12-23T05:11:49.000Z","dependencies_parsed_at":"2022-09-03T16:51:46.462Z","dependency_job_id":null,"html_url":"https://github.com/azer/javascript-guide","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Fjavascript-guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Fjavascript-guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Fjavascript-guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Fjavascript-guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azer","download_url":"https://codeload.github.com/azer/javascript-guide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860190,"owners_count":21173342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-07T00:17:45.719Z","updated_at":"2025-04-14T10:12:18.545Z","avatar_url":"https://github.com/azer.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"* [Code Functions As Much As Possible](#code-functions-as-much-as-possible)\n* [Compose Large Abstractions From Small Modules](#compose-large-abstractions-from-small-modules)\n* [Write Declarative Code](#write-declarative-code)\n* [NPM Everywhere](#npm-everywhere)\n* [Require \u0026 Export on Top](#require--export-on-top)\n* [Avoid `new`, `prototype` and `this`](#avoid-new-prototype-and-this)\n* [While Loops Are Faster and Simpler](#while-loops-are-faster-and-simpler)\n* [Declare Variables Outside of Statements](#declare-variables-outside-of-statements)\n\n## Code Functions As Much As Possible.\n\n* Create functions that does only one thing.\n* Avoid declaring functions with `var` statement\n\n```js\nfoo()\nbar()\n\nfunction foo(){}\nfunction bar(){}\n```\n\n## Compose Large Abstractions From Small Modules\n\n* Create modules that does one thing. \n* Create repositories for modules and publish/open source them on NPM and Github if possible.\n* Never couple your code with any dependency doing more than it should\n* Avoid frameworks\n\nA good read about this topic: http://substack.net/many_things\n\n## Write Declarative Code\n\n* Write less code\n* Write code that tells what it does briefly\n* Choose simple \u0026 short variable names\n\n## NPM Is Everywhere\n\n* Modularize your JS in CommonJS.\n* Use [browserify](http://github.com/substack/node-browserify)\n* Avoid other module systems like RequireJS.\n\n## Require \u0026 Export on Top\n\n```js\nvar foo = require('foo')\nvar bar = require('./bar')\n\nmodule.exports = {\n  qux: qux,\n  corge: corge\n}\n\nfunction qux(){}\nfunction corge(){}\n```\n\n## Avoid `new`, `prototype` and `this`\n\nFunctions returning objects will let you avoid maintaining \"this\" arguments and also let you benefit from\nfunctional programming.\n\n```js\nvar smith = Child('Joe', 'Smith')\n\nfunction Child(parent, name){\n  return {\n    parent: parent,\n    name: name\n  }\n}\n```\n\nAnd keep your code available for functional programming:\n\n```js\nvar JoeChild = partial(Child, 'Joe')\n\nvar smith = JoeChild('Smith')\nvar kat = JoeChild('Kat')\n\nsmith.parent\n// =\u003e Joe\n\nkat.parent\n// =\u003e Joe\n```\n\n## Declare Variables Outside of Statements\n\nDeclaring variables inside of a statement will make your code work and look less consistent. For example, below code will fail when you run it:\n\n```js\nfoobar\n```\n\nWith the error of \"ReferenceError: foobar is not defined\". But following code will not fail;\n\n```js\nfoobar\n\nif (false) {\n  var foobar\n}\n```\n\nFor having better consistency, declare the variable on top of your statement;\n\n```js\n\nvar foobar\n\nif (false) {\n  foobar = whatever\n}\n```\n\n## While Loops Are Faster And Simpler\n\nWhile loops are faster than for loops, and they're much simpler. Here is an example;\n\n```js\nvar i = 10\n\nwhile (i--) {\n  console.log(i)\n}\n```\n\nThis will output from 9 to 0. If you'd like the other way:\n\n```js\nvar i = -1\n\nwhile (++i \u003c 10) {\n  console.log(i)\n}\n```\n\n![](https://dl.dropboxusercontent.com/s/prfjx7c33zm8x9o/npmel_0.jpg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazer%2Fjavascript-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazer%2Fjavascript-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazer%2Fjavascript-guide/lists"}