[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-707218-105":3,"detail-sidebar-cat-0-en-105":80,"doc-detail-707218-en":130,"doc-similar-707218":161},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":73,"head_meta":75,"extra_data":77,"updated_unix":79},105,"en","javascript-style-guideversion-21-guidelines-for-javascript-code-formatting-indentation-and-spacing","JavaScript Style Guide—Version 2.1 - Guidelines for JavaScript code formatting - Indentation and spacing","","JavaScript Style Guide Version 2.1 provides formatting and coding conventions for writing JavaScript, aligning with the SICP JS language adaptation used in the Structure and Interpretation of Computer Programs course book. It specifies limits for line length and tab/newline indentation, rules for block indentation and brace placement in functions and conditionals, and requirements to always use braces. It also defines consistent layout for conditional expressions, discourages unnecessary parentheses, and establishes spacing rules between operators and operands, including argument alignment strategies.",{"@graph":14,"@context":72},[15,34,55],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/technology/","Technology",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/javascript-style-guideversion-21-guidelines-for-javascript-code-formatting-indentation-and-spacing/707218/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/javascript-style-guideversion-21-guidelines-for-javascript-code-formatting-indentation-and-spacing/707218.png","ImageObject",300,407,{"name":42,"@type":43},"noah","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-26","2026-11-14",true,{"@type":52,"interactionType":53,"userInteractionCount":30},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68],{"name":59,"@type":60,"acceptedAnswer":61},"What is the maximum recommended line length in this style guide?","Question",{"text":62,"@type":63},"Newline characters should be indented so that lines do not exceed 80 characters, and the book targets at most 70 characters per line.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"How should braces be placed for function declarations and conditional statements?",{"text":67,"@type":63},"For function declarations, the opening brace is placed at the end of the line that starts with the keyword function, separated from the parameter list by one space. For conditionals, the opening brace of the consequent block is at the end of the line starting with if, and else appears on the same line as the closing brace with one space before and after else.",{"name":69,"@type":60,"acceptedAnswer":70},"What rules apply to conditional expressions and operator spacing?",{"text":71,"@type":63},"Conditional expressions should place consequent and alternative expressions either on the same line as the predicate (if they fit) or aligned under the predicate start. Parentheses around the predicate are generally avoided, and operator spacing should use a single space between operators and operands.","https://schema.org",{"og:url":32,"og:type":74,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":76,"canonical":32},"index,follow",{"doc_id":78,"site_id":7},707218,1794696414,{"code":4,"msg":81,"data":82},"success",[83,87,91,95,100,104,109,114,119,122,126],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":84,"show_sort_weight":85,"slug":86},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":88,"show_sort_weight":89,"slug":90},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":92,"show_sort_weight":93,"slug":94},"Exam",70,"exam",{"id":96,"doc_module":4,"doc_module_name":25,"category_name":97,"show_sort_weight":98,"slug":99},5,"Comic",60,"comic",{"id":101,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":102,"slug":103},6,50,"technology",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},7,"Healthcare",40,"healthcare",{"id":110,"doc_module":4,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},8,"Research & Report",30,"research-report",{"id":115,"doc_module":4,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},9,"Religion & Spirituality",20,"religion-spirituality",{"id":117,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":117,"slug":121},"World Cup","world-cup",{"id":123,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":123,"slug":125},10,"Lifestyle","lifestyle",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":96,"slug":129},19,"General","general",{"code":4,"msg":81,"data":131},{"doc_id":78,"user_id":132,"nickname":42,"user_avatar":133,"doc_module":4,"category_id":101,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":30,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":115,"language":139,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":140,"faqs":141,"seo_title":142,"seo_description":12,"update_tm":79,"read_time":143,"preview_page_count":33,"preview_urls":144},1099529839121,"https://ap-avatar.wpscdn.com/davatar_994ba38a5ba835b3df7d355c54d3ed8d","JavaScript Style Guide—Version 2.1  \nMartin Henz  \nNational University of Singapore  \nSchool of Computing  \nSeptember 22, 2026  \nThis is the style guide for the JavaScript §1-4 sublanguages used in the book Structure and Interpretation of Computer Programs, JavaScript Adaptation (SICP JS) . In the beginning of a firstyear course, instructors may just encourage adherence to the style, and then gradually enforce adherence in order to improve communication between learners and staff.  \nLine Length and tabs  \nNewline characters should be indented such that lines should not be longer than 80 characters. The book uses at most 70 characters per line.  \nBlocks  \nThe body of blocks are indented by four characters more than their surrounding program.// good example  \nconst x = 1;{  \nconst y = 2;  \ndisplay(x + y);  \n{  \nconst z = 3;  \ndisplay(x + y + z);  \n}  \n}  \nFunction declarations  \nThe brace that starts the body of a function declaration is placed at the end of the line that starts with the keyword function. It is separated from the parameter list by one space. Example:  \nfunction make_adder(x) { function the_adder(y) {  \nreturn x >= 0 ? x + y : -x + y;}  \nreturn the_adder;}  \nJavaScript syntax enforces that there cannot be a newline in a return statement between the keyword return and the return expression.  \n// illegal JavaScript  \nfunction square(x) { return  \nx * x;}  \nSICP, JavaScript Adaptation, JavaScript Style Guide, Version 2.0 2  \nConditional Statements  \nThe brace that starts the consequent block of a conditional statement is placed at the end of the line that starts with the keyword if. The keyword else is in the same line as the brace that ends the consequent block and has one space before and after the keyword, followed by the brace that starts the alternative block.  \n// good example  \nfunction make_abs_adder(x) { function the_adder(y) {  \nif (x >= 0) {  \nreturn x + y;  \n} else {  \nreturn-x + y;  \n}  \n}  \nreturn the_adder;}  \nAlways use braces... even if the block consists of only one statement. This is required here, and recommended in JavaScript generally.  \n// good example if (\u003Cpredicate>) {  \nreturn x + y;} else {  \nreturn x * y;}  \n// bad example (illegal here)  \nif (\u003Cpredicate>)  \nreturn x + y;  \nelse  \nreturn x * y;  \n// even worse  \nif (\u003Cpredicate>) return x + y;  \nelse return x * y;  \nSICP JS always uses else... even if the alternative block is empty. An empty block is written as {} with no space or newline between the braces.  \n// good example  \nfunction signal_error(p, x) { if (p) {  \nerror(x, \"fatal error, bad value found:\");} else {}  \n}  \n// bad example (space in empty block)  \nfunction signal_error(p, x) { if (p) {  \nerror(x, \"fatal error, bad value found:\");} else {  \n}  \n}  \nConditional expressions  \nThe consequent and alternative expressions of conditional expressions are either in the same line as the predicate (if they fit), or they are aligned under the beginning of the predicate. Examples:  \nSICP, JavaScript Adaptation, JavaScript Style Guide, Version 2.0 3  \n// good style function abs(x) {  \nreturn x >= 0 ? x : -x;}  \n// good style function abs(x) {  \nreturn x > 0  \n? x  \n: x === 0  \n? 0  \n: -x;}  \n// good style  \nconst aspect_ratio = landscape ? 4 / 3 : 3 / 4;  \n// bad style: wasted lines  \nconst aspect_ratio = landscape  \n? 4 / 3  \n: 3 / 4;  \nAvoid parentheses around the predicate. Note that conditional expressions have lower precedence than all other operators in JavaScript (except the assignment operator =, so parentheses around the predicate are rarely needed.  \n// good style function abs(x) {  \nreturn x >= 0 ? x : -x;}  \n// bad style function abs(x) {  \nreturn (x >= 0) ? x : -x;}  \nIf the consequent-expression or alternative-expression are lengthy, use indentation, but align all clauses of a conditional expression without further indentation.  \n// good style function A(x,y) {  \nreturn y === 0  \n? 0  \n: x === 0  \n? 2 * y  \n: y === 1  \n? 2  \n: A(x- 1, A(x, y-1));}  \n// bad style: line too l","cbCaikw7jY55L9xn","https://ap.wps.com/l/cbCaikw7jY55L9xn","pdf",131440,"English","# Line Length and tabs\n# Blocks\n# Function declarations\n# Conditional Statements\n# Conditional expressions\n# Operator combinations\n# Arguments and parameters","[{\"question\":\"What is the maximum recommended line length in this style guide?\",\"answer\":\"Newline characters should be indented so that lines do not exceed 80 characters, and the book targets at most 70 characters per line.\"},{\"question\":\"How should braces be placed for function declarations and conditional statements?\",\"answer\":\"For function declarations, the opening brace is placed at the end of the line that starts with the keyword function, separated from the parameter list by one space. For conditionals, the opening brace of the consequent block is at the end of the line starting with if, and else appears on the same line as the closing brace with one space before and after else.\"},{\"question\":\"What rules apply to conditional expressions and operator spacing?\",\"answer\":\"Conditional expressions should place consequent and alternative expressions either on the same line as the predicate (if they fit) or aligned under the predicate start. Parentheses around the predicate are generally avoided, and operator spacing should use a single space between operators and operands.\"}]","JavaScript Style Guide—Version 2.1 - Guidelines for JavaScript code formatting - Indentation and spacing | PDF",23,[145,149,153,157],{"page_no":22,"url":146,"width":147,"height":148},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-15/f0f7ab479122881d52c8f33a6f4f2722.webp",983,1390,{"page_no":26,"url":150,"width":151,"height":152},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-15/289ca15635008b175697c110e6965a95.webp",982,1388,{"page_no":30,"url":154,"width":155,"height":156},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-15/dc7faa40974400e37c395699548d75b6.webp",981,1387,{"page_no":33,"url":158,"width":159,"height":160},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-15/4ee2108dd8a63721b5d7811f0d842a4c.webp",980,1385,{"list":162,"token":11},[163,170,176,182,188,195,201,207,213,219],{"doc_id":164,"doc_title":165,"file_type":137,"home_preview_img_url":166,"slug":167,"view_count":168,"category_name":29,"create_tm":169},116935,"Machine Learning and Artificial Intelligence in Data Visualization - Thesis Report","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229834440596/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=WBcRHVLUoe9LfEt60JMsCLHxodw%3D","machine-learning-and-artificial-intelligence-in-data-visualization-thesis-report",22,1785672627,{"doc_id":171,"doc_title":172,"file_type":137,"home_preview_img_url":173,"slug":174,"view_count":101,"category_name":29,"create_tm":175},682223,"Python PEP8 style guide - Cheat Sheet - Naming conventions - Maximum Line Length and Line Breaking - Indentation - Comments - Code Layout","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999427735/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=W%2BQFvNaLdyb1dyZy9TM%2B%2Bzvp2zA%3D","python-pep8-style-guide-cheat-sheet-naming-conventions-maximum-line-length-and-line-breaking-indentation-comments-code-layout",1793963021,{"doc_id":177,"doc_title":178,"file_type":137,"home_preview_img_url":179,"slug":180,"view_count":101,"category_name":29,"create_tm":181},672868,"Google's R Style Guide - Coding Style Rules","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229990161141/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=z3VrUvJ6f9fkQIPNfvGOIbxRG6k%3D","googles-r-style-guide-coding-style-rules",1793611796,{"doc_id":183,"doc_title":184,"file_type":137,"home_preview_img_url":185,"slug":186,"view_count":30,"category_name":29,"create_tm":187},697391,"Learning JavaScript - A Hands-On Guide to the Fundamentals of Modern JavaScript","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230009804094/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=4Ilw9htvwqmhgUnZKEEyKroNO%2BM%3D","learning-javascript-a-hands-on-guide-to-the-fundamentals-of-modern-javascript",1794438282,{"doc_id":189,"doc_title":190,"file_type":137,"home_preview_img_url":191,"slug":192,"view_count":193,"category_name":29,"create_tm":194},391872,"Full Stack Development with React & Node JS - Live Course - Course Overview, Benefits, and Q&A","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229917709569/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=Jrn0ldcdn9%2FR25v9uDEitIAPNDo%3D","full-stack-development-with-react-node-js-live-course-course-overview-benefits-and-qa",17,1790359630,{"doc_id":196,"doc_title":197,"file_type":137,"home_preview_img_url":198,"slug":199,"view_count":22,"category_name":29,"create_tm":200},760082,"The KatePart Handbook","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230044495366/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=KUsme1JGcp2OxCvR%2F%2Fau99Xi91Y%3D","the-katepart-handbook",1795898446,{"doc_id":202,"doc_title":203,"file_type":137,"home_preview_img_url":204,"slug":205,"view_count":33,"category_name":29,"create_tm":206},685683,"JSON - Quick Guide - Overview - Syntax - Datatypes","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999686685/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=ssW1fmv09ZNJCNL8bZ8qUE82Ago%3D","json-quick-guide-overview-syntax-datatypes",1794016574,{"doc_id":208,"doc_title":209,"file_type":137,"home_preview_img_url":210,"slug":211,"view_count":110,"category_name":29,"create_tm":212},489246,"Switching from Final Draft to Highland 2 - User Guide","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229927212918/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=%2B4A7Lxsa6s3wDX%2B90fiE1nJ8bA0%3D","switching-from-final-draft-to-highland-2-user-guide",1790821541,{"doc_id":214,"doc_title":215,"file_type":137,"home_preview_img_url":216,"slug":217,"view_count":193,"category_name":29,"create_tm":218},347403,"C Programming for the Absolute Beginner - Overview","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229911501711/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=j07%2Fg91mOESd3PkpDWPOWtxQUD4%3D","c-programming-for-the-absolute-beginner-overview",1790066796,{"doc_id":220,"doc_title":221,"file_type":137,"home_preview_img_url":222,"slug":223,"view_count":105,"category_name":29,"create_tm":224},699571,"BashGuide - About This Guide - Understanding Bash","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010750079/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=EgaTFW0z820YF1YniFesfzKUi7k%3D","bashguide-about-this-guide-understanding-bash",1794479404]