Binding, Functions and Control Flow - Reading Assignment

  • What is an expression?
  1. a fragment of code that produces value
  • What is a binding?
  1. Catches and holds values. Let is the special keyword indicating the sentence is going to define a binding. (Value grasping tenticles)
  • What is an environment?
  1. A collection of bindings and their values that exist at a given time.
  • What is a function?
  1. A piece of program wrapped in value. Such values can be applied in order to run the wrapped program.
  • Give an example of a function.
  1. prompt(“Enter passcode”);
  • What is a side effect?
  1. A change in the internal state of the machine in a way that will effect the statements that come after it. Showing a dialog box or writing text to the screen.
  • Give an example of a function that produces a side effect and another function that produces a value.
  1. (Function Value e.g.)
    Console.log(Math.max(2,4);
    // --> 4

(Side-effect e.g.)
var count = 0;
function increaseCount(val){
count += val;
}

  • What is control flow?
  1. Statements executed like a story from top to bottom. ---------->
  • What is conditional execution?
  1. Not a straight road, a branching road where programs take branches based on situations at hand.
  • What kind of keyword do you need to use to invoke conditional execution?
  1. The if keyword
1 Like
  1. An expression is a fragment of code that produces a value.
  2. A binding is a keyword that “binds” to a certain expression to catch and hold values.
  3. An environment is the collection of bindings and values at a certain time.
  4. A function is a piece of program wrapped in a value.
  5. prompt(“Enter passcode”);
  6. A side effect is when a dialog box or writing text is sent to the screen.
  7. alert(“Hello World”); console.log(Math.max(5,10) + 32);
  8. Control Flow is when you have multiple functions in your program. The computer will read the functions from the top to the bottom.
  9. Conditional Execution is where the pathway forward in the program branches and has 2 paths. Based on the conditions, the program decides which direction to take.
  10. if and else
1 Like

1.What is an expression?
A fragment of code that produces value.

  1. What is a binding?
    Catcher or Holder of values or Variables

  2. What is an environment?
    Collection of Bindings and Values

  3. What is a function?
    Piece of program wrapped in a value,.

  4. Give an example of a function.
    jame = 6
    roy = 4
    function countjr (jame,roy)
    {
    retunr jame + roy ;
    }
    countjr jame +roy

  5. What is a side effect?
    A dialog Box or Text written to the screen.

  6. Give an example of a function that produces a side effect and another function that produces a value.
    function plus(x, y) { return x + y; } side effect.

var sayit = “Hello”;
var toall = “Everyone”;
var text = “Greetings are :” + sayit + toall ;

  1. What is control flow?
    When the program has more than two statements, it is executed from top to bottom.

  2. What is conditional execution?
    When the program has several branches and the program take one of them is called “Conditional Execution”

  3. What kind of keyword do you need to use to invoke conditional execution?
    if and else.

1 Like
  1. An expression is the part of a statement that produces a value.

  2. You use a binding when you want to hold and remember a value.

  3. The environment is what is already there when you start up a program.

  4. A function is a block of reuseable code designed to perform a particular task when called upon.

  5. function write( 3,6,9 );

  6. A side effect is anything that shows up outside of the program .

  7. A function with a side effect : alert(“Bitcoin baby!”);
    A function producing a value : console.log( 3+6 );

  8. The control flow is the order the statements are executed.

  9. Conditional execution is when the order of the statements depends on conditions being fulfilled or not.

  10. if
    if…else
    if…else if

1 Like

1.What is an expression?
A fragment of code that produces a value .
2.What is a binding?
A binding is a value or string set to a variable, it helps to lower the number of time you need to write the same expression in a program.
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.it executes perticular task.
5.Give an example of a function.
Console.log (""); is a function which outputs some information to the console.
6.What is a side effect?
A side effect is the observable result of a statement which modifies some state outside its scope.
interaction with its calling functions or the outside world besides returning a value
7.Give an example of a function that produces a side effect and another function that produces a value.
Prompt or alert.
8.What is control flow?
The order in which individual statements, instructions or function get process in a program.
9.What is conditional execution?
It is a function that allows the program to take a path depending to the conditions required to execute it
10.What kind of keyword do you need to use to invoke conditional execution?
If.

1 Like
  1. What is an expression?
  • Its a piece of JavaScript code that produces a value
  1. What is a binding?
  • A binding is a string to a value which is set within a program in order for the program to use until no longer necessary
  1. What is an environment?
  • A collection of bindings and and their current existing values
  1. What is a function?
  • Its a piece of program wrapped in a value
  1. Give an example of a function.
  • alert(“Hello Brian”);
  1. What is a side effect?
  • A side effect could be showing a dialogue box or writing text on the screen. Many functions are useful due to the side effects they produce. Functions may also produce values in which case they dont need side effects in order to be useful. e.g. Math.max
  1. Give an example of a function that produces a side effect and another function that produces a value.
  • console.log(Math.max(10*10)+2); produces a value
  • alert(“Hello Brian”); produces a side effect
  1. What is control flow?
  • Where you have multiple statements a control flow will execute the statements as if they are a story, from top to bottom.
  1. What is conditional execution?
  • Where the program takes the proper branch based on the situation at hand it is called a “conditional execution”
  1. What kind of keyword do you need to use to invoke conditional execution?
  • if
1 Like
  1. A fragment of code that produces a value.

  2. It catches and holds a value in JavaScript.

  3. It is a collection of bindings and their values.

  4. A piece of program wrapped in a value.

  5. prompt(“Enter passcode”);

  6. The dialog box that appears when the above function is ran.

  7. The order in which statements are executed. From top to bottom.

  8. When there is a branching road and the program takes the proper branch based on situation.

  9. if

1- an expression is any piece of code that gives a value
2- a binding is used to hold a value
3- an environment is all the bindings and their values a program has in a given state.
4- a function is a piece of program wrapped in value
5- an example of a function could be prompt(“press a key”)
6- a side effect can be created by a function, displaying text to the screen or opening a a dialogue box is a side effect
7- the binding ‘prompt(“give me your password”)’ gives the function of opening an input box for the user which is a side effect of the binding ‘prompt(“give me your password”)’
8- control flow would be the direction the computer itself would be reading and executing the code
9- conditional execution would be when the computer is asked only to execute a statement if a certain criteria is met in a previous statement.
10- ‘if’,‘else’

1 Like

Hi @AidanH!

Questions 2, 5, 6, 8, 9, 10 :ok_hand:

Here are some comments about your other answers…

Your examples ( 12 and "Hello, World" ) are correct, but…
(i) Variables are not expressions, but the values assigned to them can be (including functions).
(ii) Operators by themselves are not expressions, but when they operate on values, then, together, they produce expressions.

You haven’t understood this one, but don’t worry, I didn’t at first :wink:
An environment is made up of all the bindings (the whole bindings, not just their keywords) which are available for a program to access. As well as bindings defined within the program itself, an environment also includes a large pre-defined set of bindings, which either come already built-in to the JavaScript language, or are available in a particular environment (for example in a browser). This pre-defined set of bindings includes many standard functions which do not need to be programmed from scratch before they can be invoked (with their function names) to perform specific tasks or computations e.g. alert() , Math.max()  … etc.

A function is a reusable “mini-program” placed within a value. It isn’t a keyword, but it’s declared using the keyword function, just as variables are declared using the keywords let, const, or var .

Yes :+1:

Nearly, but not quite…
This is a good example because it combines both types of function, but you’ve got them a bit mixed up:
Math.max()  is the function that, as you say, returns a value (“the largest number which is 4”), but this isn’t a side effect.
console.log() is the function that produces the side effect: printing to the console. It prints to the console whatever is within its parentheses, which in this case is another function. And so as you rightly say:

I hope this makes things clearer, and does confuse you! Let me know if you would like me to explain anything further. :slightly_smiling_face:

By the way, you finished with a great example of conditional execution using if...else statements! :muscle:

2 Likes

Hi @Kraken!

Just a few additional comments…

More specifically, it binds a value to a variable name.

Kind of…
An environment is made up of all the bindings which are available for a program to access. As well as bindings defined within the program itself, an environment also includes a large pre-defined set of bindings, which either come already built-in to the JavaScript language, or are available in a particular environment (for example in a browser). This pre-defined set of bindings includes many standard functions which do not need to be programmed from scratch before they can be invoked (with their function names) to perform specific tasks or computations e.g. alert() , Math.max() … etc.

Yes… and these “checks” result in a decision about which “branch” to execute, and the decision is based on whether a condition evaluates to true or false.

1 Like

Hi @Jesse_Newman!

Just a couple of additional comments…

… and which are available for a program to access.

Yes… and the situation it bases its decision on is whether the condition evaluates to true or false.

Hi @pascaldeb!

Just a few additional comments…

Question 3

… and which are available for a program to access.

Question 7

Watch your upper/lower case letters, and brackets…

console.log(Math.max(2, 4));

Question 8

Question 9

Yes… and the situation it bases its decision on is whether a condition evaluates to true or false.

1 Like

Hi @rigamortizzz!

Just a few additional comments:

… and which are available for a program to access.

prompt()   This is a function, not a binding. The prompt message (telling the user what data to input) is placed or referenced within the parentheses, and is the function argument, not the function itself, and is a type of expression.

The actual function that produces a value is Math.max(2, 4)
The console.log() you’ve wrapped it in, is a function that produces a side effect, the side effect being printing the highest number to the console.

1 Like

Hi @Davide_Coltro!

Questions 1-5, 8 and 10 :ok_hand:

… a side effect doesn’t change the program, it is a an action that occurs externally (outside the program).
For example:
(i) when alert() is called, the side effect is the pop-up box that appears in the browser (but outside the program). It’s triggered by the function which is within the program.
(ii) Your example in Question 7:

… doesn’t produce and return a value to somewhere else within the program. Instead it evaluates the expression within its parentheses and logs it to the console — the console is outside the program so this is a function that produces a side effect.
Can you think of another function, one that produces a value and not a side effect? :thinking:

Yes… and the decision about which “something” should be executed, is based on whether a condition evaluates to true or false.

2 Likes

Hi @minimull!

Questions 1-5, and 8-10 :ok_hand:

Yes :+1:

Not really… a side effect doesn’t affect the statements that follow it in the program’s control flow. It is an action that occurs externally (outside the program).

Question 7

console.log(Math.max(2, 4));

You can probably also see now that the following function doesn’t produce a side effect…

Yes… and the situation it bases the decision on, is whether a condition evaluates to true or false .

2 Likes

Great, @rbrownlow!

Just a couple of observations for you to consider…

More specifically, it binds the value to its name .  The keyword let, const, or var are used to declare the binding.

The actual function that produces a value is Math.max(5, 10)
The console.log( + 32) you’ve wrapped it in, is a function that produces a side effect, the side effect being printing the highest number + 32 (42) to the console.

1 Like

Hi @kmilo_Mart!

Good attempt! Now have a think about these following points…

… of values, yes, but not variables — variable is just another term for binding (they are the same thing).

You’ve got most of syntax correct, but in order to call your function, you need to change your last line of code to:

countjr(jame, roy);

The arguments jame and roy are placed in the parentheses and separated by a comma. They are also references to the names of your bindings, and so they “pick up” the bindings’ values and feed them into the function as parameters .

You’ve got yourself a bit confused here…
You already know that an alert pop-up box, and printing to the screen, are both examples of side effects. These are both actions that occur externally (outside of the program). You can probably see that your function doesn’t produce any external action. What would the code be for the side effects you have already given as examples? These are both coded as functions.

This code doesn’t represent a function. They are all bindings (or variables). The 3rd binding text has simply been assigned (it’s caught, or is holding) a concatenation (joining) of a string and the 1st and 2nd bindings.

Yes… and the decision about which branch to take is based on whether a condition evaluates to true or false .

I hope that helps make some of these concepts a bit clearer. Just let me know here in the forum if you have any questions or would like something explained in a different way. We’re here to help you make good progress! :smiley:

Keep on learning! :muscle:

1 Like

Thanks for the response! Helps clarify everything a lot :slight_smile:

2 Likes

1. What is an expression?
An expression is a fragment of code that produces a value.

2. What is a binding?
Bindings are what allow the program to access the values. Bindings are used to catch and hold values; they can be thought of as tentacles.

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

4. What is a function?
A function is a type of value. A function is a piece of program wrapped in a value. You can call (or invoke, or apply) a function by putting parentheses after an expression that produces a function value. Values given to functions are called arguments.
Functions can either produce side effects or or return values.

5. Give an example of a function.
console.log()

6. What is a side effect?
A side effect can change the internal state of the machine in a way that will affect the statements that come after it. 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.
A function that produces a side effect: The prompt function that produces a dialog box.
A function that produces a value:
console.log(Math.max(16, 24));
// 24
8. What is control flow?
When a program has more than one statement, the statements are executed from top to bottom.

9. What is conditional execution?
The program can go two different routes based on a Boolean value (possibly based on input from a user).

10. What kind of keyword do you need to use to invoke conditional execution?
The keyword if is used to invoke conditional execution - possibly if/else pairs.

1 Like

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

Hello sir, did you forgot to type the answer for the question # 7?

Remember you can use the “Preformatted Text” Button to encapsulate any kind of code you want to show.


I am a happy Preformatted Text box, please use me wisely!

Carlos Z.