Binding, Functions and Control Flow - Reading Assignment

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

  • What is a binding?
  • When we want to catch and hold values we do binding. It allows us to bind any expression such as 5*5 to a special keyword so that when we insert the keyword get the value of 5**5(25), after the binding this word can be used as an expression.

  • 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.
  • For example in browser environment the binding prompt hold a function that shows a little dialog box asking for user input. "prompt(“Anything you would like for input to appear”); And we could pit in the string any words we would like.

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

  • 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 - prompt, console.log
  • A function that produces a value : Math.max

  • What is control flow?
    When a program contains more than one statement, the statements are execute if they were a story top to bottom. This is a control flow.

  • What is conditional execution?
    Some programs are not straight roads so when a branching road is created where the program takes the proper branch based on the situation at hand is called conditional execution.

  • What kind of keyword do you need to use to invoke conditional execution?
  • For example words “if” and “else”.
1 Like
  1. A piece of code that produces a value

  2. A binding stores the value in it’s internal state in order to be called later.
    3.A large amount of pre- made bindings, it makes it easier to code

  3. A function is a program wrapped in a value, you are able to run a program with a function

  4. An example is prompt(“Enter Password”)

  5. Side affect is when a statement affects the world. for example displaying something on screen.

  6. prompt(“Enter Password”) for side effect and a function that produces a value is function Math.max

  7. Control flow is when a program from the top to the bottom like a story.

  8. Conditional execution is when a program doesn’t run from the top to the bottom, but ‘branches’ based on the input it has been given.

  9. An example is IF and ELSE statements.

1 Like
  1. A fragment of code that produces a value
  2. it sets a value to a variable
  3. The collection of bindings and their value that exist at a given time
  4. A piece of program wrapped in a value, or in my words, the transformation of a variable into a string or value determined by the code of that function.
  5. console.log
  6. it changes what the webpage shows
  7. prompt and console.log
  8. A visual representation of all execution paths that a program can have
  9. That’s when the path produces a fork, meaning when the program contains an “if” somewhere.
  10. if and else
1 Like
  1. A fragment of code that produces a value
  2. A method that allows you to atouch a function with a common object
  3. The collection of variables and their values that exist at a given time
  4. A piece of program wrapped in a value
  5. alert (" Good morning !")
  6. Showing a dialog box or writing text to the screen is a side effect
  7. alert (" Good morning !") - value
    confirm (" Shall we , then ?") ; -side effect
  8. Executing statements predictably, from top to bottom
    9 executing by choosing from more than one statement.
  9. ‘IF’
1 Like
  1. What is an expression?

Any fragments of code resulting in a value.

  1. What is a binding?

is a Variable containing a string. Like a container. point of reference.

  1. What is an environment?

The collection of all variables inside a program

  1. What is a function?

A section of program where specific task gets performed and can be called upon.

  1. Give an example of a function.

alert (“My name is Pendar”);
// will perform an alert on a page.

  1. What is a side effect?

Observable change in the state of the application, visible in the dialogue box in console.

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

var a = 1;
undefined
a = 1
true

  1. What is control flow?

Its the order of execution; from top to bottom.

  1. What is conditional execution?

It has two or more conditions, and will perform conditions that happen to be true.

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

“if”

  1. What is an expression?
    A piece of code that, once executed, produces a result.

  2. What is a binding?
    A definition in our code that allows to store a value in a variable.

  3. What is an environment?
    The set of bindings and their values at a given time and scope in our program.

  4. What is a function?
    A piece of code wrapped in a value.

  5. Give an example of a function.
    alert(‘When moon?’);

  6. What is a side effect?
    An action derived from an execution of a function.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    The alert function produces a pop up message. The Math.abs function returns the absolute value of an input number.

  8. What is control flow?
    Deciding which part of the code will be executed.

  9. What is conditional execution?
    Changing the control flow of our program depending on some conditions.

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

1 Like
  1. A fragment of code that produces a value is an expression.
  2. To catch and hold values, JavaScript provides a thing called a binding, or variable. It is like a tentacle reaching out for a certain value assigned to it most recently.
  3. The collection of bindings and their values that exist at a given time is called the environment.
    4-5. A function is a piece of program wrapped in a value. E.g. prompt (“ABC”);
  4. Showing a dialog box or writing text to the screen is a side effect.
  5. Side effect: E.g. prompt (“ABC”);
    Value: console.log(Math.max(2, 4));
  6. Control flow is like a straight road, the statements are executed as if they are a story, from top to bottom.
  7. Conditional execution is like a branching road, where the program takes the proper branch based on the situation.
  8. if
1 Like

1. What is an expression?

  • Any fragment of code that produces a value; any value that is written literally; anything between parentheses and any operator is also an expression.

2. What is a binding?

  • A binding is way to store any value in any expression of your choosing. It ‘binds’ a value to an expression which can be accessed later by calling the the binding name.

3. What is an environment?

  • An environment can be defined as the collection of bindings that exist in a program at any given moment.

4. What is a function?

  • A function is a piece of code wrapped in a value that can be called at any moment.

5. Give an example of a function.

  • prompt(“Enter password”)

6. What is a side effect?

  • Any statement that could indirectly change or effect other statements that come after it.

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

  • Side effect = alert();
  • Value = console.log(Math.max(1, 2));

8. What is control flow?

  • The control flow is the way the program is being read. Top to bottom in a sequential manner.

9. What is conditional execution?

  • More than one way to execute code depending on another variable. If statements are used to define the conditions under which an alternative value will be valid.

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

  • If; else; !; else if
1 Like
  1. An expression is a piece of code that produces a value. Variables, strings and operators can also be called an expression for ex: 12; is an expression and “Hello, World”; is also an expression. These can also be called statements because of the semi colon at the end meaning the statement that 12; is over.

  2. A binding looks something like this. let johnsAge = 22; For the computer to hold a specific variable in place and let it recycle itself we use the keyword let to a) hold the variable name ie johnsAge and b) hold the expression 22 that is connected the the variable johnsAge. Instead of let you can also use var and const.

  3. The Environment is the program itself. When starting a JavaScript application the page may look empty yes but it already holds keywords you can use for binding expressions you wish to enter. Some keywords JavaScript holds are if, for, false, var, void, break, class, and many more. You wont be able to call a variable by their keyword because it is used for other functions.

  4. A function is a keyword that has a value. You can invoke, call, or apply it by using parentheses after the expression. Instead of putting var or let in front you can just put the function on itself directly. Values given to a function are called arguments and depending the function, it might need different value types.

  5. prompt(“How old are you?”);
    console.log(5+5);
    These are examples of two different functions needing different values.

  6. A side effect is when a function modifies something on the screen ie showing a dialogue box or writing text to the screen. It doesn’t have to be just changing something on the screen. As long as it modifies something else out of its own self it can be called a side effect.

  7. A good example is console.log(Math.max(2,4)). The answer the console will give is 4 which is a side effect. Because it is producing a value that is outside its region and returning a value. It counts the largest number which is 4 and returns the value 4 instead of 2 makes it a side effect. Without the side effect function it would just print to the console 2 and 4.

  8. Control flow is the way you want a program to flourish. For ex: lets say your making a program that asks you for a number and in return prints out what that number is divided by 2. First you would need the number by prompting it and then use the console.log function to print the number/2. This has to be written with the prompt on top and the function under it. That is how you control the flow of the program.

  9. A conditional execution is when you are changing the control flow to get the desired answer. For ex: if you were to prompt “What number is higher than 7” and whoever writes a number lower than that, you can add conditional executions like an if statement which can the offer something like if the number written was lower than 7, then print “that number is lower that 7”.

  10. One of the conditional executions you can use are if statements. If and else statements are like side effects that can change the control flow for ex:

var johhnyAge = 8;
var jimmysAge = 11;

if (jimmysAge > johnnyAge)
{console.log("Jimmy is older than Johnny by " + (jimmysAge - johnnyAge) + “years”)
}

else{console.log("Johnny is older than Jimmy by " + (johnnyAge - jimmysAge) + “years”)
};

… not just a string, but any value or expression which has been assigned to a name (in other words any variable).
binding = variable (two terms meaning the same thing)

I’m not too sure what you were trying to demonstrate here. A good example of a function that produces a side effect is your answer to Q5:

The side effect is the alert that pops up with your name.

Whether the condition evaluates to true or false, the program will still continue to execute, but just along different “branches”. You’re right that we can have a series of consecutive conditions :+1: and then we would end up having several alternative “routes” depending on the combination of T/F.

1 Like

Great work! :smiley:

console.log("Soon, I hope!");

:crossed_fingers: :wink:

Yes, and more specifically depending on whether the condition evaluates to the Boolean true or false.

1 Like

Great! Just a few comments…

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.

Control flow is actually what enables the computer to decide which road to take through the program from top to bottom. It’s usually not a straight road due to the control flow containing conditional executions (alternative branches) and loops (repetition) along the way.

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

Keep studying, you’re doing great! :smiley:

2 Likes

**What is an expression?
A part of code that produces a value when executed.

**What is a binding?
A binding is used to catch or hold a value.

**What is an environment?
A collection of values and bindings for a given time.

**What is a function?
A function is code wrapped in a value.

**Give an example of a function.
alert(“Ivan Loves Fungi”);

**What is a side effect?
Side effects are given from the execution of a function. It can be a text box.

**Give an example of a function that produces a side effect and another function that produces a value.
Using the Ivan Loves Fungi alert, you would see a text box appear with those words. Math.max is a function that produces a value.

**What is control flow?
Control flow is basically like reading a book. You start at the top and end at the bottom.

**What is conditional execution?
A method used to branch logic based on the input given.
For instance,
Enter a number - # Given - Show
Enter a number - Not a Number Given - Show something else

. **What kind of keyword do you need to use to invoke conditional execution?
IF and Else.
If number is given, show this
Else, show this.

1 Like

Some really good answers there! :+1:
A few comments…

You’ve pretty much got it. The value is the expression you have chosen to store. The binding “binds” this value/expression to the name. Then you are exactly right — we can then access the value (which the expression evaluates to) by referencing the name.

A side effect is some kind of meaningful action produced by a piece of code (such as a function), and which occurs externally (outside of the program) e.g. the pop-up message is a side effect of alert()

The actual function that produces a value is Math.max(1, 2)
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.

! isn’t a keyword, it’s one of the logical operators — the NOT operator. We can use it along with && and ||  in our condition. Then the keywords you’ve correctly mentioned are what actually control the flow based on whether our condition evaluates to true or false.

2 Likes
  • What is an expression? code returning a value
  • What is a binding? it binds a value to an variable
  • What is an environment? Its the collection of bindings in a program
  • What is a function? a fucntion performs a task
  • Give an example of a function. prompt(“Enter your private key here”)
  • What is a side effect? a side tasks that can be performed by a function, not to return a value
  • Give an example of a function that produces a side effect and another function that produces a value. side effect print(anaconda), pure function: math.max(4,3)
  • What is control flow? top to bottom execution
  • What is conditional execution? using if checks to execute
  • What kind of keyword do you need to use to invoke conditional execution?
    [/quote] if
1 Like

An Expression is a fragment of code that produces a value.
A Binding is a way to capture and hold values for later use in code
An Environment is the collection of bindings and their values that exist at a given time
A function is a piece of program wrapped in a value
Example of Function - Prompt(“enter passcode”);
Showing a dialog box or writing text to the screen is a side effect. A lot of
functions are useful because of the side effects they produce.
If a statement or function modifies the state of something else, then it is
producing a side effect.
console.log(math.max (2, 4)); // 4
Control Flow - When your program contains more than one statement, the statements are
executed as if they are a story, from top to bottom.
Conditional Execution is where the program takes the proper branch based on the
situation at hand.
Keyword for Conditional Execution “if”

1 Like

1 a fragment of code that produces a value

2 to catch and hold values java script provides a thing called a binding or variable

3 the collection of bindings and their values that exist at a given time is called the environment

4 function is a piece of program wrapped in a value

5 prompt (“enter passcode”)

6 show a dialog box or writing tekst to the screen is a side effect

7 side effect: prompt (“enter passcode”)
value : console.log (math.max 2, 4)

8 from top to bottem the statements are executed (straight line)

9 branche route, where the program takes the proper branche based on the situation

10 the if keyword

Thank you Jon for the support! It is much clearer now! :slight_smile:

1 Like
  1. What is an expression?
    A fragment of code that produces a value. Every value
    that is written literally is an expression.
  2. What is a binding?
    The special word (keyword) indicates that this sentence is going to define a binding. It is followed by
    the name of the binding and, if we want to immediately give it a value, by an = operator
    and an expression.
  3. What is an environment?
    The collection of bindings and their values that exist at a given time.
  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.
  5. Give an example of a function.
    in a browser environment, the binding prompt holds a function that shows a little dialog box asking for
    user input.
  6. What is a side effect?
    Showing a dialog box or writing text to the screen is a side effect of a functions.
  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));
    // → 4
  8. What is control flow?
    The order in what statements will be executed.
  9. What is conditional execution?
    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.
  10. What kind of keyword do you need to use to invoke conditional execution?
    if
1 Like
  1. An expression is a fragment of code that produces a value.
  2. A binding is a variable with a name: with the assignment (=), we can give a value to the name of the variable.
  3. The environment is the collection of bindings and their values that exist at a given time.
  4. A function is a piece of program wrapped in a value.
  5. function averageOf2 (num1, num2){
    return (num1 + num2)/2;
    }
  6. A side effect is something that change the state of a program in a way that will affect it.
  7. alert(“alert is a function that produces a side effect”);
    console.log(2+4); produces a value.
  8. Control flow is the order in which we code and have our statements evaluated.
  9. Conditional execution is something that is execute if something happens.
  10. if (else) keyword.
1 Like