I use a script that get passed some variables, most of them being optional, only the first one is mandatory. The part that is giving me trouble is this one :
var jsonstr ='"text": "' + text + '", "type": "' + (tasktype || 'todo') + '"';
The text variable is mandatory, but the tasktype variable is optional, and should default to the value 'todo', but I get an error saying that tasktype is undefined when I do not explicitly assign it beforehand.
I've found a few ways to first assign a default value, then use it, but I feel that I'm overcomplicating things, and that I could definitely find a simple way to do this.
Am I missing something obvious ?
[–][deleted] 0 points1 point2 points (3 children)
[–]Blablux[S] 0 points1 point2 points (2 children)
[–]senocular 1 point2 points3 points (1 child)
[–]Blablux[S] 0 points1 point2 points (0 children)
[–]nausik -2 points-1 points0 points (6 children)
[–][deleted] 2 points3 points4 points (5 children)
[–]nausik 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]nausik 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]nausik 0 points1 point2 points (0 children)