Can't Use "+=" in Chrome Console?!?!


#1

Why’s this happening, please?

I know you can’t do document.write() in the console so is this case a similar situation??

Thanks!


#2
 > a = 5
   b = 1
   console.log(a+=b)
   6
<- undefined
 > a
<- 6

#3

There’s not really a why to that, what you wrote doesn’t make sense, it’s a case of “why would you be able to?”, much like why a rock on your kitchen table doesn’t dance. The second version isn’t any better.
Entirely unrelated to chrome.

Argue for what you’re doing and why it would be written that way instead.


#4

Also, note that we cannot augment a variable that is just being declared/defined.


#5

Okay, thanks, LOL – you have can be very circumspect in the way you say things sometimes…just like a language parser!!


#6

Yes, I finally saw what I did there…boy these error messages are really less than helpful: instead of alerting me that my logic was wrong, it sent me off in a totally wrong direction, making me think my syntax was wrong!!

Why do the parsers do that?? Why not just say “something doesn’t make sense here” instead???


#7

What do you mean by “augment”…I understand the everyday English but not in a JavaScript context.


#8

To augment means to increase. += is an augmentation assignment that requires the object on the left to be a defined value that matches the type of the assignment on the right. undefined cannot be added to a number.


#9

Ah, you mean “increment” – is “augment” really a term in JavaScript? Just curious. I just did a quick Google search for “augment javascript” but still ain’t sure.

But okay, thanks, so we can’t declare a variable and then in the same expression or statement an operation on it. Got it!


#10
increment => add 1
augment   => increase by any amount

It’s a word in the English language which means to increase. In JS this could be by addition, multiplication or exponentiation, or in the case of strings, by concatenation.

Language is meant to make us think. If you want everything spelled out for you like ducks in a row, then you are dreaming. Don’t forget to turn on your thinking cap so the language being communicated is assimilated into learning. Do forget the jargon and petty bothers. Get to work coding and completing lessons. It will all unfold eventually.


#11

Heehee…I see…no wonder you’re so good at this!

Thanks; good point. Though the problem I have with computer programming is that, in a very real sense, I gotta put on a significantly dumbed-down sort of thinking cap – and I don’t know which “size” to use, how dumbed-down the thinking cap must be!

So right now I’m too human for a computer and becoming sometimes too computer-like for humans!


#12

In Taoism there is an expression, the minute you think you have your finger on it, it moves (paraphrase). We can know a thing very well but there is still something to learn about it. Just like in sports, we develop our natural ability through ‘reps’. Eventually we are able to branch out and take on greater challenges. With each new challenge we cannot help but discover something new about the concept, and also about ourselves.


#13

This confirms what we spoke of earlier…

>>> s = c = 0
>>> s, c += 2, 1
SyntaxError: illegal expression for augmented assignment
>>> 

#14

Indeed – but I think that they were specifically referring to the dynamic ever-changing nature of this universe, not “simply” that there’s more to know about something even when we think we already know…

Certainly, and for me learning programming is just a stepping stone towards getting into the physical sciences and, eventually, mathematics…I’m 45 and have spent most of my life researching philosophy, history, psychology (including art and literature) and now, having at long last satisfied myself fairly well enough with MVP (Minimum Viable Product)-type of answers to questions concerning The Eternal Verities, I’m finally ready to pursue more “left-brain” stuff!

So thanks for all your assistance on my new journey!


#15

Double-touché!

Thanks for that. Don’t know why googling “augment javascript” didn’t turn up anything – but maybe it’s a general computer science term…though syntax error messages are not exactly known for their semantics!!


#16

For the record, that is a syntax error in another language (Python) but describes it beautifully since there are two parts to the expression.

    a = a + 2
      ^ -----  augment a
      ^
    assign to a

    =>  a += 2

#17

Oh, well, thanks for fully annotating the record and correcting my misunderstanding, then!

So there is no “augment” in JavaScript, just as my fruitless googling had suggested. Though I certainly concede the point that this is a general computer science word…well, I’m working on learning general CompSci – but first I’ve got to figure out me JS basics!! o_0


#18

Start with separating the human language from the jargon. That will make things easier.


#19

Yes, indeed – hence my previous frustration at knowing which “size” of “dumbed-down” thinking cap to use!

Sometimes I’m too “literal-minded” for a high-level language like JavaScript, and other times I’m too" broad-minded" for what is still computerese, after all!

Something of a case in point would be my latest question on these forums at Different Switch Statement "Initial Evaluations" – just for an example… :wink:


#20

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.