What is the difference between printing `3 + 4` and `'3 + 4'`?

Perfectly explained.

You are asking the computer to do two different things. If you use 3 +4, you are asking the computer to use the add operator to add together the numbers 3 and 4 and show you the sum in the console. If you use β€˜3 + 4’ with the quotations, you are asking the computer to show you the string of text 3 + 4.

for number 3 you could just use console.log(34);

The difference is you use the quotes it would understand that is a string and not a sum.

thanks so much. i think this is what OP was asking- it’s the same curiosity I had. In a sense, I just wanted to be able to β€œshow my work” in a string on a single line while using an operator. inserting the comma allows this, or, as you put it, it allows us to concatenate,

I guess I get it now. So "console.log(3+4) "will print 7 but β€œconsole.log(β€˜3+4’)” will print 3+4. I feel this is similar to Python in that regard.

In the first case console.log (3 + 4), it prints the result of the sum of 3 plus 4. In the other case console.log (β€˜3 + 4’), the string 3 + 4 is printed.

When you log in 3+4 in the console the result would be 7,
but when you log in β€˜β€˜3’’+β€™β€˜4’’ or β€˜3’+β€˜4’ you get the result as 34,
I hope you understood the answer of your question :smiley: :smiley:

Hi.
The difference is you use the quotes it would understand that is a string and not a sum.
If you are asking the computer to do a sum use console.log( 3+4) and the result is 7.
But, if you want to add the operator and show you the sum in the console. You should use
console.log(β€˜3 + 4 =’,3+4);
with the quotations to show the strings and 3+4 to show the answer.
I hope this helps you.

Hi,
console.log(β€˜3+4’) prints 3+4 without the quotation mark.
console.log(’ β€˜3+4’ ') prints β€˜3+4’ with the quotation mark.

Good!, you explained very well showing the different between the number and the string, you add numbers and combine string

This exercise shows the dynamic nature of Javascript: you don’t need to compute in advance the outcome of a computation, you can compute it on the output instruction (console.log()). It may simplify code and the fact that you may print the computation using quotation mark may help users to understand where the outcome came from, but in a web environment, that’s hard to be useful. It’s a deep understanding exercise.

anything we write inside a quote JavaScript will assume its a string so if we type
console.log(3+4) OUTPUT: 7
console.log(β€œ3+4”) OUTPUT: 3+4

Excellent explanation. Thank you :+1:

I know that this adds a lot to the discussion. :+1:

console.log(β€˜3’+β€˜4’); will result in a string.
console.log(34); will result in a number
(even though both will be shown as 34 in the console

(3 + 4) is numbers so its result at 7, but (β€œ3 + 4”) is a string well by 3+4.-

3+4 is the correct way to calculate number in JavaScript, while β€˜3+4’ print the same value (It takes it like a string).