Binding, Functions and Control Flow - Reading Assignment

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

  • What is a binding?
    A binding allows JavaScript to catch and hold values. It is enabled by using the keyword “let” followed by the name of the binding which is connected to an expression (which yields a value as expressions do) using the = operator.

Eg

Let me = “Kiwan”;

console.log(me);

//Kiwan

  • What is an environment?
    The environment is the collection of bindings and their values that exist at a given point in time. Environments are not empty when a program starts up and may contain mission critical bindings that facilitate the language standard and user interface hardware peripherals like reading mouse and keyboard inputs.

  • What is a function?
    A function is code or part of a program than is represented by a value.

  • Give an example of a function.
    console.log() ,outputs a value to the console

  • What is a side effect?
    A side effect occurs when a function shows a dialog box or writes to the screen.

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

alert("Hello") /* is a function that produces a side effect 
in the form of a text box that says Hello*/
function difference(x, y) { return x-y};  /* defines the
 name of the function as "difference"*/ 
difference(50, 40); /* invokes the function by 
substituting values for x and y which returns 10.*/
  • What is control flow?
    Statements within a program are executed from top to bottom. Certain statements may be skipped or carried out depending on if conditions set above it are met or not. The resulting sequence of statements being executed is the control flow.

  • What is conditional execution?
    Execution of code only if certain conditions are met.

  • What kind of keyword do you need to use to invoke conditional execution?
    The keyword if

1 Like
  1. What is an expression?
    Expression is any piece of code that produces a value
  2. What is a binding?
    Binding is when a program stores values internally so that they can be used later.
  3. What is an environment?
    A collection of bindings and their values at any given time.
  4. What is a function?
    A function is a group of code that can be called by the program to compute a value.
  5. Give an example of a function.
    prompt(“Enter passcode”);
  6. What is a side effect?
    Side effect opens a window asking for passcode.
  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.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?
    Conditional execution is when a code is executed only if a condition fulfilled
  10. What kind of keyword do you need to use to invoke conditional execution?
    if, else
1 Like

6. What is a side effect?

Quite close sir, A side effect is any secondary effect or reaction that comes from an action we take. Side effects can be either good or bad, but are generally unintended. In functional programming, side effects are any state change that can be seen outside of a function call, with the exception of the function return value.

Hope this gives you a clear view of the subject, keep learning! :slight_smile:

If you have any doubt, please let us know so we can help you!

Carlos Z.

1 Like
  1. An expression is a piece of code that produces a value.
  2. Binding, also known as ‘variable’ - catches and hold values but not tied to the value forever. A change is the ‘expression’ will change the binding value.
  3. An environment is a set of bindings and their values that exist at a particular give time and it’s always ready to be used to load a website, read mouse, and process keyboard inputs.
  4. A function is a fragment of program enclosed in a value.
  5. An example of a function: prompt("…")…this function opens a dialog box.
  6. A side effect is an alteration to the internal state of a program that will have an effect on the statements after it.
  7. The prompt(“What is your name?”) has a side effect of the dialog box that pops up, yet a function that produces a value would look like this: console.log(Math.min(7,9)); 7 is the value.
  8. A control flow converts a value to a number in the order of a code. Straight line control flow for statements to be evaluated.
  9. A conditional execution is for programs that don’t only take a straight-line control flow but also a situational flow based on what is at hand and what type of execution it needs. A few examples are: if, else, else if.
  10. Keyword to invoke a type of execution is “if” & “else”.
1 Like

Hi @Lucky_Mkosana,

Mostly good answers :ok_hand:

I would also add that the decision about which “branch” to take is based on whether a condition (a Boolean expression) evaluates to true or false . This is key to how conditional execution operates within a program.

Keep on learning! :muscle:

3 Likes

Thank you kindly for checking. @jon_m

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

  2. What is a binding?
    A binding is a key word (eg. let/var) used to hold a value so it doesn’t disappear and can be referred to again

  3. What is an environment?
    The environment is a record of bindings and their values

  4. What is a function?
    I have tried to research this further but I’m not really sure how to best explain it/understand it. Seems like it’s another type of expression? But the function will only be executed if something invokes it?

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

  6. What is a side effect?
    Some functions produce side effects (eg. Dialog box or writing text to the screen)

  7. Give an example of a function that produces a side effect and another function that produces a value.
    Alert function produces an text box that you need to click out of - alert(“hello”);
    Return function that returns a value - console.log(Math.max(2, 4)); // → 4

  8. What is control flow?
    Control flow is the order that the functions are executed. It runs from top to bottom.

  9. What is conditional execution?
    Conditional execution means that a function will be executed only IF certain conditions hold. Instead of the functions running from top to bottom, there will be separate branches depending on which conditions are met

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

1 Like
  1. Piece of code that returns value
  2. Binding is a kind of pointer to a certain value
  3. It’s a collection of bindings and their values in a certain frame of time.
  4. It’s a piece of program wrapped in a value
  5. prompt(“Your text”);
  6. A function or expression that changes the state of the application
  7. alert(“This is a side effect”);
    console.log(“This produces a value”)
  8. It’s the order of executing statements in a script
  9. A function that is going to be executed in case of defined result
    10.if
1 Like

Thank you for that! Much appreciated

1 Like

thanks, i will try to do every day some time, a little bit trying to improve a little bit…

1 Like
  1. It is a fragment of code that produces a value.

  2. Binding is that of giving an element a value so it can be stored in it.

  3. It is a collection of bindings and their unique values in a certain time frame, before they dissipate.

  4. A function is a piece of code wrapped together in a value. That function then can be executed by “applying” it.

  5. An example is, prompt (“enter date of birth”).

  6. Side effects happen when a statement changes environment or the internal state of the hardware and affects the statement that comes after it.

  7. function addSeven(value){
    return value+10;
    }

    function multiplyBy3(val){
    val*3;
    }

  8. Control overflow is the order in which statements are executed in the “story”.

  9. Conditional execution is where the program takes the direction based on the situation at hand.

  10. We need (if, else, and else if).

1 Like

Hi @Jody,

Some very nice answers! I can see you’ve put a lot of thought into this! :+1:

Here are a few points to help clarify some of the concepts…

… you’ve pretty much got it. The keyword declares the binding. It’s the binding’s name (which follows the keyword) that is assigned the value and “holds onto” it. When we want to access the value, it’s the binding’s name that we use to reference it.

See if this helps…

A function is a reusable “mini-program”. The code of this mini-program will have been written to perform a specific task or computation, and will execute each time the function is called (invoked) with its name (the one it has been assigned to) appended with parentheses. The parentheses contain any required arguments — values fed into the function as parameters, and sometimes needed for the function to execute successfully. Functions return values to wherever in the program they are called from, or they can produce side effects outside of the program, or sometimes both.

If you just change the word function to code/program, your description is very good :slightly_smiling_face:

Conditional execution means that a piece of code will be executed only IF certain conditions hold. Instead of this part of the program running from top to bottom, there will be separate branches depending on which conditions are met.

Conditional execution can occur within functions, outside of functions, and the code executed in each alternative branch can be a function or another type of statement.

1 Like

Some nice answers here, @sherlock!

A couple of observations…

This is actually another example of a function that produces a side effect: logging a message to the console.

… not just a function, but any piece of code that will be executed…and then I would also add that the decision about which “branch” to take is based on whether a condition (a Boolean expression) evaluates to true or false . This is key to how conditional execution operates within a program.

1 Like

This was really helpful! Thank you @jon_m

1 Like

A fragment of code that produces a value.

Binding associate variables with values, and tie them together.

A collection of bindings and the values associated with them.

A piece of program wrapped in a value. Normally is a section of code that performs a certain task when given a set of values.

alert(sum(a,b));

When there is a shown output such as dialog or pop up window.

Side Effect: prompt(“How old are you”);
Value: console.log(Math.max(10, 21));

The order the in which the code is read, top to bottom. you can use entered data, in a function later, and then display it.

When the program has to decide which path to take based on the parameters set in the function.

“IF”.

1 Like

Hi @Christian_S,

Nice answers :ok_hand:
Just one observation…

The decision about which path to take is based on whether a condition (a Boolean expression) evaluates to true or false . This is the key to how conditional execution operates within a program. Conditional execution can occur anywhere within a program, not just within functions. Be careful about using the term parameters: a parameter is a value passed to a function when it it is called (or invoked).

1 Like

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

2. What is a binding?
It is used to catch and holds values.

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

4. What is a function?
It is a piece of a program wrapped in a value.

5. Give an example of a function.
alert(“Hello World”); // Pop-up

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

7. Give an example of a function that produces a side effect and another function that produces a value.
alert(“Hello World”); // Pop-up Side effect
Math.max(30,12) // Produces a value

8. What is control flow?
Statements executing as is if they are a story, from top to bottom.

9.What is conditional execution?
When a program should behalve differently depending on the situation at hand.

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 leads to a value. An expression corresponds to a sentence fragment, a javascript statement corresponds to a full sentence. A program is a list of statements.

  2. What is a binding?
    A binding is the name of a variable that points to a value. Once created it can be used as an expression. A binding is defined by initially typing the keyword ‘let’ followed by it’s name then adding an = operator followed by an expression. It points to a value that can be changed. Binding names must not start with a digit. may include digits, $ or _ but no other special characters, or keywords with special meaning such as ‘let’.

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

  4. What is a function?
    A function is a piece of program wrapped in a value. You can call a function by putting parentheses () after an expression that produces a function value. A lot of values provided in the default environment have the type function. Values given to functions are called arguments.

  5. Give an example of a function.
    In the browser environment, the binding ‘prompt’ holds a function that shows a small dialogue box asking for user input.

  6. What is a side effect?
    A side effect is a function that eg shows a dialog box or writes text to the screen.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    ‘prompt’ produces a side effect, a dialogue box asking for input
    ‘Math.max’ produces a value, picking the largest number from a series of numbers.

  8. What is control flow?
    Control flow is the way a program is read and executed apon being read from top to bottom. In a straightforward simple manner, eg do this, then do this etc. it is known as a straight line control flow.

  9. What is conditional execution?
    This is where the program can execute a different branch response depending on the input it receives.

  10. What kind of keyword do you need to use to invoke conditional execution?
    ‘if’ and maybe ‘else’ (boolean operators) for two paths to choose from, and multiple ‘if’ and ‘else’ pairs (chains) if you need more paths…

1 Like

What is an expression?
A fragment of code that produces a value is called an expression
What is a binding?
A binding is a variable which holds a value for later use.
What is an environment?
The collection of bindings and their values that exist at a given time is called
the environment
What is a function?
A function is a piece of program wrapped in a value
Give an example of a function.
prompt(“Enter passcode”);
What is a side effect?
A statement could display something on the screen—that counts as changing the world—or it could change the internal state of the machine in a way that will affect the statements that
come after it. These changes are called side effects

Give an example of a function that produces a side effect and another function that produces a value.
Showing a dialog box or writing text to the screen is a side effect.console.log(Math.min(2, 4) + 100);
// → 102
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
What is conditional execution?
The program executes based on situation at hand is called conditional execution
What kind of keyword do you need to use to invoke conditional execution?
If and else

1 Like

Hi @Tordek,

Great answers! :muscle:

Yes :+1: … and I would just add that this involves the program deciding between two or more separate “branches”, and that this decision is based on whether a condition (a Boolean expression) evaluates to true or false . This is key to how conditional execution operates within a program.

2 Likes