So I'm using a shorthand javascript if/else statement (I read somewhere they're called Ternary statements?)  this.dragHandle.hasClass('handle-low') ? direction = "left" : direction = "right"  This works great, but what...
ES6 introduced a shorthand notation to initialize objects with functions and properties.    // ES6 shorthand notation const obj1 = {     a(b) {         console.log("ES6: obj1");     } };  // ES5 var obj2 = {     a: function a(b) {         con...
I'm wondering if there's a shorter way to write this:  var x = 1; if(y != undefined) x = y;   I initially tried x = y || 1, but that didn't work. What's the correct way to go about this?...
I try to avoid repetition in my code as much as possible. I know you can turn this:  variable = variable+2   into this  variable += 2   but how can I avoid repetition here? Surely there is a way...  this.className = this.className.replace("classn...
I am trying to get better at shorthand.  Can someone help clarify the below?      (obj.getValue("title")) ? message += "\ntitle: " + obj.getValue("title") : null;   Is it, if obj has a title then add it to the message otherwis...
This is my first question here on Stack Overflow. I generally find all my answers from searching but I'm completely out of motivation after writing the following code.  Is there a more efficient way or short-hand to write the following code?  Cur...
Many of us have seen / use the following:  var t=!0; (t will equal true) var t=!1; (t will equal false)   How safe is this method of evaluating true / false?  I see google use this all the time.  Will these ALWAYS return a boolean true / false?  Than...
I have a variable and if that variable is a object I would like to call a method on that object, if not I want to do nothing.  I'm wondering if there is any reason why I shouldn't do it like this.  var foo = null;    /////////////////////////...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.