Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3211738
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:45:55+00:00 2026-05-17T14:45:55+00:00

I’d like to incorporate whatever shorthand techniques there are in my regular coding habits

  • 0

I’d like to incorporate whatever shorthand techniques there are in my regular coding habits and also be able to read them when I see them in compacted code.

Anybody know of a reference page or documentation that outlines techniques?

Edit: I had previously mentioned minifiers and it is now clear to me that minifying and efficient JS-typing techniques are two almost-totally-separate concepts.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T14:45:56+00:00Added an answer on May 17, 2026 at 2:45 pm

    Updated with ECMAScript 2015 (ES6) goodies. See at the bottom.

    The most common conditional shorthands are:

    a = a || b     // if a is falsy use b as default
    a || (a = b)   // another version of assigning a default value
    a = b ? c : d  // if b then c else d
    a != null      // same as: (a !== null && a !== undefined) , but `a` has to be defined
    

    Object literal notation for creating Objects and Arrays:

    obj = {
       prop1: 5,
       prop2: function () { ... },
       ...
    }
    arr = [1, 2, 3, "four", ...]
    
    a = {}     // instead of new Object()
    b = []     // instead of new Array()
    c = /.../  // instead of new RegExp()
    

    Built in types (numbers, strings, dates, booleans)

    // Increment/Decrement/Multiply/Divide
    a += 5  // same as: a = a + 5
    a++     // same as: a = a + 1
    
    // Number and Date
    a = 15e4        // 150000
    a = ~~b         // Math.floor(b) if b is always positive
    a = b**3        // b * b * b
    a = +new Date   // new Date().getTime()
    a = Date.now()  // modern, preferred shorthand 
    
    // toString, toNumber, toBoolean
    a = +"5"        // a will be the number five (toNumber)
    a = "" + 5 + 6  // "56" (toString)
    a = !!"exists"  // true (toBoolean)
    

    Variable declaration:

    var a, b, c // instead of var a; var b; var c;
    

    String’s character at index:

    "some text"[1] // instead of "some text".charAt(1);
    

    ECMAScript 2015 (ES6) standard shorthands

    These are relatively new additions so don’t expect wide support among browsers.
    They may be supported by modern environments (e.g.: newer node.js) or through transpilers. The "old" versions will continue to work of course.

    Arrow functions

    a.map(s => s.length)                    // new
    a.map(function(s) { return s.length })  // old
    

    Rest parameters

    // new 
    function(a, b, ...args) {
      // ... use args as an array
    }
    
    // old
    function f(a, b){
      var args = Array.prototype.slice.call(arguments, f.length)
      // ... use args as an array
    }
    

    Default parameter values

    function f(a, opts={}) { ... }                   // new
    function f(a, opts) { opts = opts || {}; ... }   // old
    

    Destructuring

    var bag = [1, 2, 3]
    var [a, b, c] = bag                     // new  
    var a = bag[0], b = bag[1], c = bag[2]  // old  
    

    Method definition inside object literals

    // new                  |        // old
    var obj = {             |        var obj = {
        method() { ... }    |            method: function() { ... }
    };                      |        };
    

    Computed property names inside object literals

    // new                               |      // old
    var obj = {                          |      var obj = { 
        key1: 1,                         |          key1: 5  
        ['key' + 2]() { return 42 }      |      };
    };                                   |      obj['key' + 2] = function () { return 42 } 
    

    Bonus: new methods on built-in objects

    // convert from array-like to real array
    Array.from(document.querySelectorAll('*'))                   // new
    Array.prototype.slice.call(document.querySelectorAll('*'))   // old
    
    'crazy'.includes('az')         // new
    'crazy'.indexOf('az') != -1    // old
    
    'crazy'.startsWith('cr')       // new (there's also endsWith)
    'crazy'.indexOf('az') == 0     // old
    
    '*'.repeat(n)                  // new
    Array(n+1).join('*')           // old 
    

    Bonus 2: arrow functions also make self = this capturing unnecessary

    // new (notice the arrow)
    function Timer(){
        this.state = 0;
        setInterval(() => this.state++, 1000); // `this` properly refers to our timer
    }
    
    // old
    function Timer() {
        var self = this; // needed to save a reference to capture `this`
        self.state = 0;
        setInterval(function () { self.state++ }, 1000); // used captured value in functions
    }
    

    Final note about types

    Be careful using implicit & hidden type casting and rounding as it can lead to less readable code and some of them aren’t welcome by modern Javascript style guides.
    But even those more obscure ones are helpful to understand other people’s code, reading minimized code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I would like to count the length of a string with PHP. The string
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.