Binding, Functions and Control Flow - Reading Assignment

  1. What is an expression?

Values dirived from operands and operators

  1. What is a binding?

A variable

  1. What is an environment?

the framework which within, you will find all the variables

  1. What is a function?

It is and expression wrapped in a value

  1. Give an example of a function.

Math.min

  1. What is a side effect?

A statement that has an effect on the outside world

  1. Give an example of a function that produces a side effect and another function that produces a value.

Side effect - alert(). Value - Math.max

  1. What is control flow?

The conditions that map out the flow of execution

  1. What is conditional execution?

Expressions that comply with if and else statements

  1. What kind of keyword do you need to use to invoke conditional execution?

if, else, else if

1 Like

The part of code that produces a value is known as an expression.

A binding or variable, allows a value to be kept so that it can be used by other parts of the program. The statement age=10+5 takes the result of the expression 10+5 and stores it in a binding called age.

The bindings and values in a program are together referred to as the environment.

A program can also be wrapped in a value. This is known as a function. Functions are blocks of code designed to perform a frequently required task. Once a function has been defined it is likely to be called many times.

A function can be called by referring to the value it is bound to. Any values that the function requires can be sent to it between parentheses after the function name e.g.

prompt (“Enter your age”);

This statement will invoke a function called prompt and will give it the value Enter your age. The function will then display Enter your age and obtain a value from the user.

A function writing to the screen is known as a side effect. Not all functions produce a side effect some just produce a value e.g.

Math.max(1,2);

A function with a side effect is shown below:

Alert (Math.max (1,2));

Control flow is the sequence in which statements in a program are executed. Generally statements are executed sequentially starting from the top of the program. However some statements such as if can affect the sequence in which the next statement will be executed. A conditional statement, for example if, can cause a different sequence of statements to be executed in the event a particular condition is met.

1 Like
  1. What is an expression?
    Expression is A fragment of code that produces a value. such as (2+3)

  2. What is a binding?
    Binding is kind of strings to grab some value. Like hands in our body.

  3. What is an environment?
    I don’t know.

  4. What is a function?
    the function is a pieces of the program with a wrapped value. Like organ in our body, such as the liver.

  5. Give an example of a function.
    prompt(“hey, IVAN”);
    console.log(“hey, Felip”);

**What is a side effect?
I don’t know

  1. Give an example of a function that produces a side effect and another function that produces a value.
    I don’t know

**What is control flow?
control flow is like a story that is logically connected.

**What is conditional execution?
set some conditions to the expression to control the output.

1 **What kind of keyword do you need to use to invoke conditional execution?
if \ else

1 Like
  1. What is an expression?
    A fragment of code that produces a value is called an expression.
  2. What is a binding?
    To catch and hold values, JavaScript provides a thing called a
    binding, or variable
  3. What is an environment?
    The collection of bindings and their values that exist at a given time is called
    the environment.
  4. What is a function?
    A function is a piece of program wrapped in a value.
  5. Give an example of a function.
    Math.max(2, 4)
  6. What is a side effect?
    Showing a dialog box or writing text to the screen is a side effect.
  7. Give an example of a function that produces a side effect and another function that produces a value.
    Math.min(2, 4) + 100
  8. What is control flow?
    When your program contains more than one statement, the statements are
    executed as if they are a story, from top to bottom.
  9. What is conditional execution?
    A branching road, where the program takes the proper branch based on the
    situation at hand is called conditional execution.
  10. What kind of keyword do you need to use to invoke conditional execution?
    If, else if, else
1 Like

Hi @umeshusoda,

Nice answers :ok_hand:

Just one comment…

Yes… and usually (but not always), depending on whether this condition evaluates to true or false (i.e. whether the condition is met or not), only one of two alternative branches of code will be executed next.

1 Like

Hi @Amri2020,

Q3, 4, 5, 7, 8, 10 :ok_hand:

However, look carefully at my following comments, as several of your answers are confused, and I recommend you review the concepts introduced in this assignment again:

No…that’s a statement.

An expression is any piece of code that evaluates to (produces) a value. It can be as simple as a single primitive value, or a more complex interaction of values, operators and sub-expressions; a function can also be an expression when it is assigned to a variable name.


Yes :+1:

No…
…the value is connected (or assigned) to a variable name. This is like a label, and represents the value assigned to it. The variable name can be used to reference the value it “holds” within other parts of the program which are within the variable’s scope.

I think the definition in the course book refers to the fact that, like a value is assigned to a variable name, so too a function is bound to a function name, such that when the function is called by referencing it’s name, the function’s code block (mini-program) is executed.

Most functions return values, so in that sense your understanding of the opposite makes sense. However, some functions don’t return values (they may just produce a side effect) and so in this respect the value is the function itself, rather than existing within it.

No… this is what I was explaining above. A side effect is not a value produced (or returned) by a function. It is some kind of meaningful action produced by a function, which either occurs externally (outside of the program) or affects some other part of the program, other than by just returning a value.

The term control flow describes the order in which the different parts of the program are executed (or not). Therefore, conditional execution affects the program’s control flow by requiring a decision to be made between alternative branches of code. This decision about which branch to execute is based on whether a condition evaluates to true or false.

1 Like

Hi @Bunbo_Hue,

Your answers are excellent, and you have clearly given a lot of thought to the different concepts :+1:

Just one comment…

Correct :+1:

No…
console.log() produces a side effect — logging the output to the console. An example of a function that produces a value is:

Math.max(5, 9);     // => 9 is the value produced (or returned)
2 Likes

Hi @Hamze_Dirir,

Nice answers :ok_hand:

Just one observation…

I think you mean  prompt()

1 Like

Hi @Mining365,

Nice answers :ok_hand:

Just a couple of comments…

Correct :+1:

No…
console.log() produces a side effect — logging the output to the console. An example of a function that produces a value is:

Math.max(5, 9);     // => 9 is the value produced (or returned)

Yes… and the decision about which of the alternative paths to follow is based on whether a Boolean expression evaluates to the Boolean value true or false (i.e. whether a condition is met or not).

Hi @MasterofCoin

Your answers are mostly OK :ok_hand:

Here are a few comments…

This is one type of expression, yes… but more generally, an expression is any piece of code that evaluates to (produces) a value. So, as well as being a more complex interaction of values, operators and sub-expressions, it can also be as simple as a single primitive value.

…OK, but what is a variable? We’re looking for a more detailed description, to check you actually understand what it is.

Again, this doesn’t really explain what it is: what do these expressions do in the context of if...else statements? How do they affect the program’s control flow?

Thanks jon_m
i appreciate the wisdom

1 Like

@jon_m yes that what i meant lol… :facepunch: :love_you_gesture: :sweat_smile:

1 Like

3. What is an environment?

A collection of bindings and their values existing in an instance. By instance we mean the hole program environment, all the functions, logic, variables, expressions that contains on it.

6. What is a side effect?

A side effect refers to when a piece of code does not return a value, but instead does something else like printing text to the console or displaying a prompt window.

7. Give an example of a function that produces a side effect and another function that produces a value.

alert(“Hello im alert function, i produce a side effect!”);
var NoSideEffect = true;

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

  1. An Expression is an amount of code that has a value as an end result.

  2. A Binding is is sentence that holds values attributed to them.

  3. An Environment is a group of Bindings with their values that are present at any given time.

  4. A Function is part of a program that is encased in a value.

  5. console.log is a function.

  6. A Side Effect is where the function modifies some variable outside of its environment.

  7. a. let num = Number(prompt(“Pick a number”)); this opens a dialog box in Chrome.
    b. console.log(Math.min(2, 4) + 100);

  8. Control Flow is where one statement is run first then a second statement is executed after the first statement has be executed. One leads on from the other.

  9. Conditional Execution is where the program may take different paths this will keep the program on the correct path.

  10. Keywords use to invoke conditional execution are if, let and else.

1 Like

What is an expression?
A fragment of code that produces a value is called an expression. Every value
that is written literally (such as 22 or “psychoanalysis”) is an expression. An
expression between parentheses is also an expression, as is a binary operator
applied to two expressions or a unary operator applied to one.
If an expression corresponds to a sentence fragment, a JavaScript statement
corresponds to a full sentence. A program is a list of statements.
The simplest kind of statement is an expression with a semicolon after it.

What is a binding?
To catch and hold values, JavaScript provides a thing called a
binding, or variable:
let caught = 5 * 5;
You should imagine bindings as tentacles, rather than boxes. They do not
contain values; they grasp them—two bindings can refer to the same value
Example:
let luigisDebt = 140;
luigisDebt = luigisDebt - 35;
console.log(luigisDebt);
// → 105

What is an environment?
The collection of bindings and their values that exist at a given time is called
the environment. When a program starts up, this environment is not empty. It
always contains bindings that are part of the language standard, and most of the
time, it also has bindings that provide ways to interact with the surrounding
system.

What is a function?
A function is a piece of program wrapped in a value. Such values can be applied
in order to run the wrapped program.
Give an example of a function.
For example, in a browser environment,
the binding prompt holds a function that shows a little dialog box asking for
user input. It is used like this:
prompt(“Enter passcode”);

What is a side effect? Showing a dialog box or writing text to the screen is a side effect.
Give an example of a function that produces a side effect and another function that produces a value.
Side effect function: prompt(“Enter passcode”);
Value Producing Function:
console.log(Math.max(2, 4));
// → 4

What is control flow? The control flow is the order in which the computer executes statements in a script

When your program contains more than one statement, the statements are
executed as if they are a story, from top to bottom. Below is an example
let theNumber = Number(prompt(“Pick a number”));
console.log("Your number is the square root of " +
theNumber * theNumber);

What is conditional execution?
Not all programs are straight roads. We may, for example, want to create
a branching road, where the program takes the proper branch based on the
situation at hand. This is called conditional execution.

What kind of keyword do you need to use to invoke conditional execution?
If.
Conditional execution is created with the if keyword in JavaScript. In the
simple case, we want some code to be executed if, and only if, a certain condition
holds. We might, for example, want to show the square of the input only if the
input is actually a number.
let theNumber = Number(prompt(“Pick a number”));
if (!Number.isNaN(theNumber)) {
console.log("Your number is the square root of " +
theNumber * theNumber);
}

1 Like
  1. What is an expression?
    A piece of code that resolves to a value
  2. What is a binding?
    a way to store data. it contains a piece of information
  3. What is an environment?
    A set of variables and their given state in memory during a given time
  4. What is a function?
    an expression wrapped in a value. You can then call this function to execute it.
  5. Give an example of a function.
    alert(“I love crypto!”);
  6. What is a side effect?
    If a function that changes something visually when called (i.e. dialog box pops up on screen)
  7. Give an example of a function that produces a side effect and another function that produces a value.
    alert(“Hello”); produces a side effect and
  8. What is control flow?
    the direction of execution of code, which happens from the top down
  9. What is conditional execution?
    When a function determines wether or not to execute certain parts of the code.
  10. What kind of keyword do you need to use to invoke conditional execution?
    if
1 Like

----Message d’origine----

  1. A fragment of code that produces a value
  2. A binding is a variable
  3. Collection of bindings and values at any given time
  4. A function is a piece of a program wrapped in a value
  5. prompt(“Enter Passcode”);
  6. When a function shows a dialog box or writes text to the screen
  7. alert(“Memes”), console.log(Math.min(2, 4))
  8. When the program flows from the first command down
  9. When the program takes branches based on if statements
  10. if/else
1 Like
  1. What is an expression?
    A fragment of code that produces a value
  2. What is a binding?
    binding is. variable, it holds value
  3. What is an environment?
    A collection of bindings and values at a given time.
  4. What is a function?
    A piece of program wrapped in a value
  5. Give an example of a function.
    prompt(“enter name”)
  6. What is a side effect?
    Shows a dialog box or writing text to a screen
  7. Give an example of a function that produces a side effect and another function that produces a value.
    prompt(“enter happiness level”)
    Console.log(Math.max(5,15));
  8. What is control flow?
    The way the code is read when you have more than one statement
  9. What is conditional execution?
    a branching road for the code
  10. What kind of keyword do you need to use to invoke conditional execution?
    If
1 Like
  1. What is an expression?
    A fragment of code that produces a value is called an expression.

  2. What is a binding?
    You should imagine bindings as tentacles, rather than boxes. They do not contain values; they grasp them—two bindings can refer to the same value.
    The words var and const can also be used to create bindings, in a way similar to let.

  3. What is an environment?
    The collection of bindings and their values that exist at a given time is called the environment.

  4. What is a function?
    A function is a piece of program wrapped in a value. Such values can be applied in order to run the wrapped program.
    Values given to functions are called arguments.

  5. Give an example of a function.
    prompt(“Enter passcode”);

  6. What is a side effect?
    Showing a dialog box or writing text to the screen is a side effect.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    prompt(“Enter passcode”);
    console.log(Math.max(2, 4));

  8. What is control flow?
    The way the code is read when you have more than one statement.

  9. What is conditional execution?
    Code that isn’t read like a completely straight line, but branches of based on conditions.

  10. What kind of keyword do you need to use to invoke conditional execution?
    If

1 Like