Can i declare a variable like below?
var new_result_data_flag-- =1;
its giving error of ReferenceError: Invalid left-hand side in assignment.
Can i declare a variable like below?
var new_result_data_flag-- =1;
its giving error of ReferenceError: Invalid left-hand side in assignment.
It's very basic question in the programming world, 'how to create and initialize the variable'
You can do like
var new_result_data_flag = 10
// if you want to subtract value from the same variable then do as below
new_result_data_flag -= 1 // is equals to new_result_data_flag = new_result_data_flag - 1
console.log(new_result_data_flag) // 9
Short answer: no.
Not only can you not declare variables as such, you shouldn’t even want to if it was possible. It would be confusing for the reader.
The double minus operators perform a post/pre decrement operation, i.e., subtracts one from the variable and returns the decrement value (pre-decrement ) or the original value (post-decrement).
Your statement attempts to decrement a non-initialized value which would be confusing at best.
If you however simply need to have this naming scheme you could use an object property as such:
var bla = {};
bla['new_result_data_flag--'] = 'fluffy';
even you can use like this.
var new_result_data_flag_ =1;
console.log(new_result_data_flag_);
and my suggestion for variable declaration Names