understanding the use of javascript statements

Viewed 105

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')

2 Answers

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.

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

Related