0

I have seen a bunch of articles talking about "what is an expression in Js?" but some of them said that "an expression in Js is any piece of code that produces a value" like this one 4 + 4, so this one is of course an expression the value that this will produce is 8, but what about if we only a single value of type:x, like this: 4, they also said that this is an expression but this really doesn’t match or isn’t too accurate with the previous definition, and the other case is that if we do this x = 2, that is considered also an expression an if we move forward x is also an expression, so, what really is an expression? is there different types of expression in Js? which ones are this? what are they differences? what is the really accurate definition for this concept?, please someone with this knowledge I really appreciate if you can clarify this to me!

10
  • 3
    There is one kind of expression, and it is defined by the language grammar. The JavaScript grammar is very complicated so that's not the best place to start. When you're learning the language, using a simple example like 4 + 4 is a fine way to think about what some documentation means when it says "expression". Commented Feb 1, 2023 at 20:07
  • 3
    An expression is a value, OR anything that executes and ends up being a value. Commented Feb 1, 2023 at 20:07
  • 1
    Look at a syntax diagram for js -- then it will be clear when, how, and why what things are expressions Commented Feb 1, 2023 at 20:08
  • 2
    "but this really doesn’t match or isn’t too accurate with the previous definition" - Why not? 4 is syntactically valid and produces a value. Commented Feb 1, 2023 at 20:10
  • 2
    Yes, 4+4, 4, x = 2, x all are expressions in JS code. You might want to take a look at some things that are not expressions to understand the difference. Commented Feb 1, 2023 at 20:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.