tags:

views:

41

answers:

2

I found this PDF here and in it the author describes an expression as any valid set of literals, variables, operators, function calls and expressions that evaluate to a single value i.e.

3 + 7
3 + 7 + 10 + ""
"Dr." + " " + "Pepper"

That all seems fine to me. An a statement is any set of declarations, method and function calls and expressions that performs some action i.e.

var num = 1
document.write("hello")

But later on they refer to the last line of the examples below as statements

var salutation = "Greetings, "
var recipient = "Earthlings"
salutation + recipient //statement

var greeting = "Greetings, "
greeting += "Earthlings" //statement

Why isn't salutation + recipient and greeting += "Earthlings" considered an expression when they are adding two strings like in their expression example "Dr." + " " + "Pepper"

Many thanks

+2  A: 

Because a statement can contain expressions.

A statement is any set of declarations, method and function calls and expressions that performs some action

Justin Niessner
@ Justin - Thanks for the response. I understand that a statement can contain expressions by why is salutation + recipient a statement and "Dr." + "Pepper" an expression? They are both adding strings together.
Nick Lowman
@Nick Lowman: An Expression IS a Statement. An Expression is one kind of Statement. They aren't *exclusive* categories.
S.Lott
@ S.Lott - Thanks man.
Nick Lowman
A: 

I think the first is a mistake, I suspect the author mean to type += instead of just +. The second is a statement because it's shorthand for

greeting = greeting + "Earthlings"

and you are assigning the result of the string concatenation (an expression) back to the original variable (which makes it a statement).

Paolo
@Paolo - It's all making sense now thanks
Nick Lowman