2

This question is not meant to find a solution for the task but to understand as the title says. I could not categorize the question. Without further ado. I began practicing Javascript on the website freecodecamp.org.My main concern is the set up of the function from freecodecamp.org:

for ([initialization]; [condition]; [final-expression])

Keep in mind that all these three are statements. So when I dug deeper the website w3schools.com stated that:

JavaScript statements are composed of:Values, Operators, Expressions, Keywords, and Comments.

The for loop has the following syntax:
for (statement 1; statement 2; statement 3) {
  // code block to be executed
}

w3schools.com displays strings as statements. My questions are: - Does that mean Objects can also become statements? (Since values are considered to be statements, I am referring to the Name-Value-pairs). - How are statements and parameters connected with each other? (since both are 'value-holders')

A-L
  • 57
  • 1
  • 7
  • 1
    You're messing up [syntax](https://en.wikipedia.org/wiki/Syntax_(programming_languages)) and [semantics](https://en.wikipedia.org/wiki/Semantics_(computer_science)). – Niklas E. Jun 06 '20 at 10:36
  • A `for` loop is a statement but the parts inside the loop header are not statements. They can only be *expressions* (`initialization` can also be a variable declaration). An *object literal* is an expression. There is also an *expression statement* which allows the use of an expression in a statement context. So yes, you can use an object literal everywhere a statement can be used, but that doesn’t make an object literal a statement. I’m not sure knowing this is helpful if you don’t have a good understanding of expressions and statements already. – Felix Kling Jun 06 '20 at 10:53
  • @FelixKling I do understand parts of statements and expressions. I am a beginner so giving me only parts of the puzzle is creating confusion. I tried to the copy-past learning methode like everybody else, that did not made it stick for verylong. However if I have the whole information then understanding it will be easy. For example: the usage of numbers. I knew only that mathematical operations(eg: addition, subtraction, devision, and multiplication)can occure. I didnt know about numbers create bevaiour, or decimal numbers care allowed or how a function was written. – A-L Jun 09 '20 at 15:15
  • I was mainly worried that throwing in the term `ExpressionStatement` would create more confusion than it would be helping. – Felix Kling Jun 09 '20 at 16:27
  • @FelixKling dont sweat it. I was referring to the educational setup from where I get/got my knowledge. thanks anyway – A-L Jun 10 '20 at 06:31

2 Answers2

4

Does that mean Objects can also become statements?

The answer to that is no.

I get what you mean: Of cause you can use objects to achieve "statement/operator-like meaning" within a programming language, but these properties only exist in semantics and do not become part of the syntax as actual statements or operators of the language.

There is actually a big difference between syntax and semantics when it comes to the inner logic programming languages. I don't want to dig deeper in it because that would be a bit off-topic for Stack Overflow and I'm also not an expert in Computer Science.

Niklas E.
  • 1,413
  • 4
  • 10
  • 22
3

Does that mean Objects can also become statements? (Since values are considered to be statements, I am referring to the Name-Value-pairs)

Nope. From w3schools.com, this is how they explain a statement:

This statement tells the browser to write "Hello Dolly." inside an HTML element with id="demo": document.getElementById("demo").innerHTML = "Hello Dolly.";

The reason why for loop contains three "statements":

for (statement 1; statement 2; statement 3) {
  // code block to be executed
}

Is because those statements tell the browser what to do:

Statement 1 is executed (one time) before the execution of the code block.

Statement 2 defines the condition for executing the code block.

Statement 3 is executed (every time) after the code block has been executed.


How are statements and parameters connected with each other?

They aren't.

  • Parameters are used in functions and behave as local variables in them;
  • Statements tell the browser what to do and are executed one by one.

References:

JS Statements

JS for loop

JS Function parameters

Vepth
  • 669
  • 3
  • 19