Optimizing JS codeSpanning Table Cells automatically between same value cellsMultiple .on() eventsSearch...

Rock identification in KY

Revoked SSL certificate

How does quantile regression compare to logistic regression with the variable split at the quantile?

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

What's the point of deactivating Num Lock on login screens?

What would happen to a modern skyscraper if it rains micro blackholes?

Is it possible for a square root function,f(x), to map to a finite number of integers for all x in domain of f?

DC-DC converter from low voltage at high current, to high voltage at low current

Why doesn't H₄O²⁺ exist?

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

What doth I be?

Is it unprofessional to ask if a job posting on GlassDoor is real?

Why are electrically insulating heatsinks so rare? Is it just cost?

What is the word for reserving something for yourself before others do?

Cross compiling for RPi - error while loading shared libraries

dbcc cleantable batch size explanation

Java Casting: Java 11 throws LambdaConversionException while 1.8 does not

How much RAM could one put in a typical 80386 setup?

What does it mean to describe someone as a butt steak?

Why can't I see bouncing of switch on oscilloscope screen?

LWC SFDX source push error TypeError: LWC1009: decl.moveTo is not a function

How does one intimidate enemies without having the capacity for violence?

Why is 150k or 200k jobs considered good when there's 300k+ births a month?



Optimizing JS code


Spanning Table Cells automatically between same value cellsMultiple .on() eventsSearch filter list using jQueryRead multiple files asyncUsing the $q service in AngularJS to handle promisesElegant way of processing an “options” parameterjQuery form with price formatUsing JavaScript's Array.splice with assigning the replacements item as an arrayDynamically call a function in a given moduleSimple function returning 1 if the Mean = Mode, or 0 if not






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







-2












$begingroup$


I have two variables that could be the same. In such a case I am assigning one of them to be undefined. Is this code the best way I can write it?



    let folderOwner = $("#change-folder-owner").val();
let folderUser = $("#user_name_alias").data('value');

folderOwner = (folderOwner === folderUser) ? undefined : folderOwner;


Can someone please help me with a better way?










share|improve this question









$endgroup$








  • 2




    $begingroup$
    Why should the value be undefined if they are equal?
    $endgroup$
    – dustytrash
    Mar 29 at 17:22












  • $begingroup$
    Using if can be clearer and easier to understand than the ternary operator
    $endgroup$
    – David White
    Mar 29 at 19:35










  • $begingroup$
    @dustytrash I need to use that undefined elsewhere
    $endgroup$
    – Bhargavi
    Apr 1 at 4:01


















-2












$begingroup$


I have two variables that could be the same. In such a case I am assigning one of them to be undefined. Is this code the best way I can write it?



    let folderOwner = $("#change-folder-owner").val();
let folderUser = $("#user_name_alias").data('value');

folderOwner = (folderOwner === folderUser) ? undefined : folderOwner;


Can someone please help me with a better way?










share|improve this question









$endgroup$








  • 2




    $begingroup$
    Why should the value be undefined if they are equal?
    $endgroup$
    – dustytrash
    Mar 29 at 17:22












  • $begingroup$
    Using if can be clearer and easier to understand than the ternary operator
    $endgroup$
    – David White
    Mar 29 at 19:35










  • $begingroup$
    @dustytrash I need to use that undefined elsewhere
    $endgroup$
    – Bhargavi
    Apr 1 at 4:01














-2












-2








-2





$begingroup$


I have two variables that could be the same. In such a case I am assigning one of them to be undefined. Is this code the best way I can write it?



    let folderOwner = $("#change-folder-owner").val();
let folderUser = $("#user_name_alias").data('value');

folderOwner = (folderOwner === folderUser) ? undefined : folderOwner;


Can someone please help me with a better way?










share|improve this question









$endgroup$




I have two variables that could be the same. In such a case I am assigning one of them to be undefined. Is this code the best way I can write it?



    let folderOwner = $("#change-folder-owner").val();
let folderUser = $("#user_name_alias").data('value');

folderOwner = (folderOwner === folderUser) ? undefined : folderOwner;


Can someone please help me with a better way?







javascript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 29 at 14:59









BhargaviBhargavi

1282




1282








  • 2




    $begingroup$
    Why should the value be undefined if they are equal?
    $endgroup$
    – dustytrash
    Mar 29 at 17:22












  • $begingroup$
    Using if can be clearer and easier to understand than the ternary operator
    $endgroup$
    – David White
    Mar 29 at 19:35










  • $begingroup$
    @dustytrash I need to use that undefined elsewhere
    $endgroup$
    – Bhargavi
    Apr 1 at 4:01














  • 2




    $begingroup$
    Why should the value be undefined if they are equal?
    $endgroup$
    – dustytrash
    Mar 29 at 17:22












  • $begingroup$
    Using if can be clearer and easier to understand than the ternary operator
    $endgroup$
    – David White
    Mar 29 at 19:35










  • $begingroup$
    @dustytrash I need to use that undefined elsewhere
    $endgroup$
    – Bhargavi
    Apr 1 at 4:01








2




2




$begingroup$
Why should the value be undefined if they are equal?
$endgroup$
– dustytrash
Mar 29 at 17:22






$begingroup$
Why should the value be undefined if they are equal?
$endgroup$
– dustytrash
Mar 29 at 17:22














$begingroup$
Using if can be clearer and easier to understand than the ternary operator
$endgroup$
– David White
Mar 29 at 19:35




$begingroup$
Using if can be clearer and easier to understand than the ternary operator
$endgroup$
– David White
Mar 29 at 19:35












$begingroup$
@dustytrash I need to use that undefined elsewhere
$endgroup$
– Bhargavi
Apr 1 at 4:01




$begingroup$
@dustytrash I need to use that undefined elsewhere
$endgroup$
– Bhargavi
Apr 1 at 4:01










2 Answers
2






active

oldest

votes


















4












$begingroup$

It would be clearer to use if:



if (folderOwner === folderUser) folderOwner = undefined





share|improve this answer









$endgroup$





















    1












    $begingroup$

    You can avoid re-assigning folderOwner's value. Use two separate variables for the raw values, then evaluate for folderOwner's value.



    const ownerValue = ...

    const userValue = ...

    const folderOwner = (ownerValue === userValue) ? undefined : ownerValue





    share|improve this answer









    $endgroup$














      Your Answer





      StackExchange.ifUsing("editor", function () {
      return StackExchange.using("mathjaxEditing", function () {
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
      });
      });
      }, "mathjax-editing");

      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "196"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216479%2foptimizing-js-code%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4












      $begingroup$

      It would be clearer to use if:



      if (folderOwner === folderUser) folderOwner = undefined





      share|improve this answer









      $endgroup$


















        4












        $begingroup$

        It would be clearer to use if:



        if (folderOwner === folderUser) folderOwner = undefined





        share|improve this answer









        $endgroup$
















          4












          4








          4





          $begingroup$

          It would be clearer to use if:



          if (folderOwner === folderUser) folderOwner = undefined





          share|improve this answer









          $endgroup$



          It would be clearer to use if:



          if (folderOwner === folderUser) folderOwner = undefined






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 29 at 15:18









          Oh My GoodnessOh My Goodness

          2,177315




          2,177315

























              1












              $begingroup$

              You can avoid re-assigning folderOwner's value. Use two separate variables for the raw values, then evaluate for folderOwner's value.



              const ownerValue = ...

              const userValue = ...

              const folderOwner = (ownerValue === userValue) ? undefined : ownerValue





              share|improve this answer









              $endgroup$


















                1












                $begingroup$

                You can avoid re-assigning folderOwner's value. Use two separate variables for the raw values, then evaluate for folderOwner's value.



                const ownerValue = ...

                const userValue = ...

                const folderOwner = (ownerValue === userValue) ? undefined : ownerValue





                share|improve this answer









                $endgroup$
















                  1












                  1








                  1





                  $begingroup$

                  You can avoid re-assigning folderOwner's value. Use two separate variables for the raw values, then evaluate for folderOwner's value.



                  const ownerValue = ...

                  const userValue = ...

                  const folderOwner = (ownerValue === userValue) ? undefined : ownerValue





                  share|improve this answer









                  $endgroup$



                  You can avoid re-assigning folderOwner's value. Use two separate variables for the raw values, then evaluate for folderOwner's value.



                  const ownerValue = ...

                  const userValue = ...

                  const folderOwner = (ownerValue === userValue) ? undefined : ownerValue






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 29 at 16:19









                  JosephJoseph

                  22.9k21935




                  22.9k21935






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Code Review Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216479%2foptimizing-js-code%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

                      How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

                      Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...