Binding, Functions and Control Flow - Reading Assignment

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

  2. A binding is there to catch and hold values. Javascript provides a binding by using keywords. The keyword indicates that the sentence is going to define a binding.

  3. An environment is the collection of bindings and their values that exist in that given moment.

  4. A function is an expression wrapped in a value. A lot of the values provided in the default environment have the type function.

  5. Here are a couple of examples of a function one is in a browser environment, the binding “prompt” holds a function that shows a little dialog box asking for input and another is the “alert” function which displays a pop up message.

  6. A side effect is any function which displays or changes the webpage visibly by showing a dialog box or writing text to the screen.

  7. One example of a function that produces a side effect and another function which produces a value is alert(“alert is a function”) and (Maths.max) function returns a value.

  8. Control flow is when your program contains more than one statement, the statements are executed as if they are a story from top to bottom.

  9. Conditional execution is when the program takes the proper branch based on the situation at hand. There could be a straight road and then based on the situation the program can take a branching road this is called conditional execution.

  10. The keyword you need to use to invoke conditional execution is if. You can create two separate, alternative paths using together if and else.

1 Like

Any unit of code that can be evaluated to a value is an expression.

A binding or variable trough special keywords (such as var, let and const) grasp and hold value .
It is followed by the name of the binding and, if we want to give it a value, by the = operator and an expression.

After a binding has been defined, its name can be used as an another expression. The value of such an expression is the value the binding currently holds.

Is a collection of bindings and their values that exist at a defined time.

Is a piece of code designed to perform a particular task and is executed when “something” invokes it (calls it).

prompt(“Enter Nickname”);

A side effect is basically when we change the state of the program through an indirect means.

  • I call this function
  • I get a direct result back.
  • I get some direct effect back, but I also change something else about the state of my program.

function that produces a side effect:

let theNumber = Number(prompt(“Pick a number , i will multiply for 50 times”));
console.log("Your number multiplied for 50 is " +
theNumber * 50);

function that produces a value:

console.log(Math.min(22, 44) * 10);

The control flow is the order in which the program executes statements in a script.

There is a conditional execution when we “tell” the program to perform different actions based on different conditions. It is invoked with the keywords mentioned below.

else if , else , if , switch

1 Like
  1. What is an expression? a fragment of code that produces a value, can be as short as 22, or “psychoanalysis”, Expressions can contain other expressions. Expressions don’t change anything, they merely produce values which then can be used by the program. Anything that returns a value can be called an expression.

  2. What is a binding? (or variables) enable a program to memorise values by tying the value to the binding. Bindings consist of a command (i.e. “let”) in combination with the name of the binding (keyword)

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

  4. What is a function? Functions are values representing a piece of program which come predefined with the default environment of the programming language. They can be called/invoked in order to execute their program.

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

  6. What is a side effect? Functions that influence the following statements are called side effects. These are functions with no immediate effect but change the internal state of the machine.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    Side-effect: var = 55, a = “simple”
    Function: console.log(Math.max(2, 9)); let animal = “Elephant”

  8. What is control flow? Specifies in what order consecutive statements are to be executed. This might be linear, i.e. one after the other,

  9. What is conditional execution? or the execution order can be adjusted to expand on capabilities, such as the “if / else” statement which intersect predefined conditions that have to be met before deciding which will be the next statement to be executed

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

1 Like

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

What is a binding? Bindings make programs keep an internal state, remember things….catch and hold values.

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

What is a function? A piece of program wrapped in a value. These values can be applied in order to run the wrapped program.
Give an example of a function. Dialog boxes in a web browswer asking for user input.

What is a side effect? Change the internal state of the machine in a way that will affect the statements that come after it.
Give an example of a function that produces a side effect and another function that produces a value. A side effect would be “Hello World” simply writing text to the screen. Function to value would be console.log(Math.max(2,4));
// > 4
In the above example Math.max takes any amount of number arguments and gives back the greatest.

What is control flow? When a program contains more than one statement, the statements are executed as if they are a story, from top to bottom. I cut and pasted the example in our book into the console and used the number 5. The return read, “your number is the square root of 25”. The function Number converts a value to a number, which is needed because the result of the prompt is a string value, and we want a number.

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. You may want to create a branching road, where the program takes the proper branch based on the situation at hand. Conditional execution is created with the if keyword in JavaScript. Example, want to show the square of the input only if the input is a 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);
}

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

1 Like
  1. According to the author, “an expression is a fragment of code that produces [or represents?] a value.”
  2. I don’t think that the definition of “binding,” given in the text, is fully coherent. Initially, the author defines a binding to be a variable, but then he goes on to refer to constants and functions as bindings as well. So it seems to me that a binding is really just a name of either a variable, a constant or a function. The problem, though, with that latter interpretation is that the author seems to distinguish between bindings and binding names. This makes some sense insofar as a function, for example, is more than just a name, but it still leaves me wondering exactly what the author means by a “binding.”. The word itself seems to suggest the notion of an association of a name with an entity (or value) that is being named, but a proper definition of such an association is simply not provided. (Sorry for being so exacting, but I am a professional math guy, and reading and writing precise definitions is basically what I do for a living.)
  3. According to the author, the environment at a given moment in time is the totality of all the bindings.and their values at that moment.
  4. A function is a rule of assignment that uniquely associates elements in a given domain with elements in a given range.
  5. domain: all positive integers; range: all integers greater than one; riule of assignment: f(x)=x+1.
  6. So far as I can tell, a side effect is a real-world observable change—in the CPU, in the memory, or on the screen—that is brought about by a statement and possibly affects other, subsequent statements (but again, the notion of a statement is not rigorously defined).
  7. f(a,b)=a+b produces the value a+b from the input (a,b) and prompt(string) produces a pop-up window with ‘string’ displayed on it above an input field. I wonder, though, whether the distinction is really well defined because the value a+b, it seems to me, cannot be produced without some actual real-world changes in the CPU and/or the memory.
  8. Again, I don’t think that the author defines the notion of a control flow very clearly, but so far as I can tell, a control flow is a schematic representation of the logical structure of a program.
  9. A conditional execution is a command execution that is carried out only if a certain prior condition is satisfied.
  10. ‘if’ or (‘if’ and ‘else’).
1 Like
  1. A fragment of code that produces a value is called an expression.
  2. It is a function that stores old values.
  3. It is a 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. prompt(“enter phone number”);
  6. Showing a dialog box or writing text to the screen.
  7. Side effect: prompt(“enter phone number”);
    Value: math.max(2, 4);
  8. It is the order in which the statements are executed.
  9. It is a function that is executed only when a certain condition is met.
  10. if
1 Like
  • What is an expression?
    code that produces a value

  • What is a binding?
    a variable that stores values

  • What is an environment?
    a collection of bindings and their values

  • What is a function?
    a piece of program wrapped in a value

  • Give an example of a function.
    prompt();

  • What is a side effect?
    a modification of some sort of state

  • Give an example of a function that produces a side effect and another function that produces a value.
    var a = “Hello”
    –> side effect: a=“hi”
    –> function: Number.isNaN(a);

  • What is control flow?
    Execution of statements from top to bottom

  • What is conditional execution?
    Executes a statement only if a certain condition holds

  • What kind of keyword do you need to use to invoke conditional execution?
    if(){}, else if (){} or else(){}

1 Like
  1. a fragment of code that produces a value
  2. bindings are variables
  3. collection of binding and their values
  4. A function is a piece of program wrapped in a value. Such values can be applied in order to run the wrapped program
  5. alert(“enter birthday”)
  6. Showing a dialog box or writing text to the screen
  7. console.log(Math.max(2, 4))
  8. means that the program executes one statement after the other beginning from the top
  9. If, statement: let number=(“pick a number”); if number <=10 show number; booleans is usually a true or false statement.
  10. if
1 Like

Thanks for the feedback. I’ve been reading up and studying and think I’m grasping the subject now. When I did this post, I was think I was fairly comfortable with the idea of of functions with return values so I gave as simple an example as I could think off…The side effect concept was what I was trying to wrap my head around…the reason this seemed harder to grasp is because while everything I’m seeing says to try to have pure functions and side effects are bad, to me they seem like a good idea…define variables outside of function and call on them in functions when needed…
Anyway, just to clarify…I think what you are saying is that the return value I gave is indeed an example of a return value, that has no side effects, but is a pointless function. Is that right?
I do appreciate the time and feedback very much by the way, thank you.

1 Like
  1. An expression is a fragment of code that produces a value ;
  2. A binding is a sentence that define a relation between a variable tag and its value :

Ex :

let drink = "beer!"; //binding assignment of a value `beer!`  to newly generated **drink** tentacle !//
console.log (drink);
beer!
  1. An Environment is the collection of bindings and their values existing at a certain time in a program;

  2. A function is a program wrapped in a value;

  3. To call a Function like Prompt will trigger a prompt window pop-up in the web browser :
    prompt("Fill this field with value");

  4. In the previous code, prompt invoking a windows with an entry field to collect a value is a side effect;

  5. prompt("Fill this field with value"); will produce a windowed pop-up as a side effect;
    console.log(Math.min(2, 4) + 100); will return the value 102;

  6. Control flow is a program’s statements execution path drawn according to test functions in the code.
    for example : 2a9cb022-7cbf-4ba3-8d86-9ac88398db48

  7. A conditional execution is a function that needs a boolean result to chose between two path of execution. One for True, one for False.

  8. You need those keywords : if, else, for, while, do, to trigger a conditional execution function.

3 Likes
  1. An expression is a fragment of code that makes up statements, and a program is basically a list of statements that produces side effects. An expression could be a piece of code that produces a value. The value may be a string, number or logical value. A binary operator applied to two expressions is also an expression, as i a unary operator applied to one. The ternary operator is also an expression. And every value that is written literally is an expression. You can think of this similar to how human languages work. Expressions can contain expressions just like human sentences are nested, a subsentence can contain its own subsentences and so on. “This allows us to build expressions that describe arbitrarily complex computations.”

  2. A binding is what lets JavaScript remember stuff by “binding” a value to a name, variable or constant and lets us programmers define these bindings and assign our own values as we see fit. Exept of course if we would try to define some of the reserved words or keywords that has special meaning in JavaScript.

  3. An environment is the collection of bindings and their values at any given time. A program always has an environment, even a “empty” program that just barely has code, still isn’t completely empty as it has an environment of bindings that are part of the JavaScript language standard (mentioned above).

  4. A function is a block of code or “subprogram”, designed to perform a particular task. Just like the program itself, a function consists of a sequence of statements called the function body. Values can be passed to a function, and the function will return a value. In JavaScrpit we can define our own functions using the function keyword.

  5. function showMessage() {
    alert( ‘Get rich 4 sure!’ );
    }
    showMessage;

  6. A side effect is something that “affects the world”, has an “effect” or is somehow observable. For example, displaying something on the screen or changing the internal state of the machine in a way that affects the statements that come after it. The function above has the side effect of alerting the user of a webpage “Get rich 4 sure” in a popup-box in the browser.

  7. alert(“This is a side effect”);
    console.log(1+1);

  8. Control flow is simply the order in which to execute the functions. It starts from the first line and proceeds to the last, unless something alters the control flow. For example conditional execution and loops.

  9. Conditional execution to execute a function whether or not something is true. This creates branching paths in a program and can alter the control flow.

  10. Conditional execution is created with the if keyword in JavaScript. This makes it so the following code only executes IF a certain condition holds. To create an alternate branch, the else keyword is used. If you want to have more than two paths to choose from, you can chain multiple conditions by using if / else if / else.

1 Like
  1. An expression is a ‘ fragment’ or ‘component’ of Javascript code that resolves to a value. Or, put another way, ‘any unit of code that can be evaluated to a value is an expression’

  2. A binding [or variable] is a way of assigning or defining values in the current memory as expressions or ‘components’ to be used in a statement.
    I found this definition useful; ‘Binding something in JavaScript means recording that identifier in a specific Environment Record. Each Environment Record is related to a specific Execution Context - and that binds the identifier (variable or function name) to the this keyword for that execution context.’

  3. The environment is the current active running ‘collection of bindings’ or definition state.

  4. A function is something that can resolve expression in statement into value . Or, put more exactly, ‘A function is a JavaScript procedure - a set of statements that performs a task or calculates a value. To use a function, you must define it somewhere in the scope from which you wish to call it.’

  5. A function example -
    console.log(2*2)

  6. A side effect is a change brought about by a statement that ‘changes the world’ in the sense that it has an active effect - either visibly, eg by generating a number and printing it, or non-visibly - by altering the setting or internal operation of the script so that it’s state has changed.

  7. a = 2 would produce a side effect in the sense that the letter a would now have a binding to the number 2, and therefore, a + a would now produce a value of 4.

  8. Control flow is a way of introducing - and controlling - multiple options if and when certain conditions are met.

  9. Conditional execution is a process by which certain events may or may not happen [be executed], dependent on meeting certain conditions.

  10. The keyword let is used to invoke conditional execution.

1 Like
  1. What is an expression?
    The code that produces a value.

  2. What is a binding?
    A binding, also called a variable, is to catch and hold the values.

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

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

  5. Give an example of a function.
    console.log function, which will output values to the console.

  6. What is a side effect?
    The expression and the statement may change the internal state of the machine in a way that will affect the statements that come after it, the changes are called side effect.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    a side effect: prompt(“Enter your age”);
    a value: Math.max(3,7);

  8. What is control flow?
    Multiple statements in a program are executed in an order.

  9. What is conditional execution?
    A program will take next action based on some conditions or criteria.

  10. What kind of keyword do you need to use to invoke conditional execution?
    IF and ELSE keyword;

1 Like

yes, that is a more close “return value” example. a Side effect is more likely to not return a value, it does something with a parameter, but it does not change it or create something else from the given parameter.

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

Carlos Z.

1 Like

Hi @jwafe,

Nice answers :ok_hand:

Just one comment…

Not all functions produce side effects. Some just return values. One type of side effect is when a function causes a meaningful action to occur externally (outside of the program) e.g. logging an output to the console, or generating a pop-up dialogue box.

1 Like
  1. every input that resolves to a value is an expression (f.ex: 1, a or (1+2))

  2. binding is like attaching some information to a named object. let name = “Zlatan Zlatanimovic”. So the programe now remembers that the name is Zlatan …

  3. It is a collection of bindings and their values at a given time

  4. A function is a piece of program wrapped in a value

  5. prompt(“Hello Ivan and Filip”)

  6. the effect in example 5. has the side effect of a window popping up on the screen.

  7. prompt(“Hello Ivan and Filip”) = side effet and console.log(Math.max. (2,4,7)) = value (7)

  8. Control flow means that the program runs from top to bottom. So if a program consists of more than one statement they will be executed in top to bottom order.

  9. it is a execution that is only being fulfilled if a certain statement is true.

  10. if, else

1 Like
  1. An expression is every kind of value (numbers or words) written in a line of code and which finish with a semicolon.

  2. A binding or also called a variable catch’s and holds value and connect it to another value. Bindings are not tied to values forever, the can be easy disconnected and tied to another value.

  3. A collection of bindings with their values which exist at the time the program is operating.

  4. In Haverbeke’s book a function is a piece of program wrapped in a value which can be applied to ran a program, but in my understanding, it is the value which is wrapped into the function.

  5. The draw function, not mentioned in the chapter 2, but one I used recently in a JS animation.

  6. A value produced by a function.

  7. The prompt function produces as a side effect a dialog box and the function Math.max produce a value.

  8. The way a multiple statements in code are executed.
    From top to bottom.

  9. Unlike control flow which execute the statements from to top to bottom, conditional execution is based on a specific situation and created with the key word if.

  10. The if and else keyword.

1 Like

1. What is an expression?

An expression is anytime there is a value that is written literally in JavaScript. Anything that produces a value in JavaScript is an expression.

2. What is a binding?

A binding is a way of attaching a name to a particular value. So if we want the word “ten” to hold the value of “10” then we could create a binding by writing let ten = 10;

This makes the program remember a value so it can be called upon later more easily.

3. What is an environment?

The environment is simply the collection of all bindings and their values that currently exist within a program. Kind of like how each country will have their own unique expressions, laws, social expectations, each program will have its own unique set of bindings that make up its environment.

4. What is a function?

My understanding of a function is that this a block of code designed to perform a particular task. A function can then be “invoked” or called upon to perform that task.

5. Give an example of a function.

console.log
prompt
alert

6. What is a side effect?

A side effect is a result of a function being executed, such as displaying a dialogue box or 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.

prompt(“This is a dialogue box”); - Side Effect
console.log(7+8); produces a value

8. What is control flow?

Control flow is the order in which your program’s statements are to be executed, which is done from top to bottom unless conditional execution is used.

9. What is conditional execution?

Conditional execution is when your program will take a different “path” depending on the conditions met.

For example, you can tell your program that if someone is over the age of 20 years old, to prompt them with different questions than if they are under 20 years old.

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

“if” and “else”

2 Likes

Binding, Functions and Control Flow- Reading Assignment.

What is an expression?

  1. When writing code on JavaScript, an expression is anything that is a value or anything that is giving value, that you write in fragment code. So the term expression is used to describe the.
    Example 5, “john” 2+3, are all a form of expression.
    This to is an Expression. You can have an expression with in an expression within a expression.
    function countapples = (janeapples,bobsapples) {return janeapples + bobsapple}

What is a binding?

  1. What JavaScript can do for a developer is provide a way you can hold or save, on your computer code that you gave value. There are special keywords that you can use that can save your value for future reference, one of them is called let.
    Example:
    let fun = “football”.
    next time i write fun in the console it will show under it “football”.
    or you can call for it by console.log fun.

But binding values does not mean it will remain as the value permanently. You can also assign a new value by way of expression.
Example:
fun = “tennis”
so now fun is no longer going to show “football” it will show “tennis” instead. I just changed the original binding value and giving it a new value.

What is an environment?

  1. The term the environment is used to describe the collection of bindings or variables and there values. This environment is not empty, binding is always contained in the JavaScript Language, so an example used is a web browser has an environment of preexisting fragment of code that interacts with your mouse and keyboard input. (If any more input for better understanding please share).

What is a function? & Give an example of a function.

4/5 A function is a piece of programme that is wrapped in a value. What this means, when a developer is writing code and you want to run a programme, to make it easy on JavaScript instead of a long code that preforms a specif task you want, its been made short an given a value.

An example of a function is alert. Alert function applies to create a pop up box on a web browser.
alert(“hello world”)

What is a side effect?

  1. When using some Functions that cause to have a interactions with the user on a web page like creating a text box or setting an alert, this is called a side effect. No not all function interact with the web browser in the same way so not all function cause a side effect.

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

An example of a function that cause side effect is:
promote(“enter password”)
This functions creates a dialog text box and cause a side effect.

A function that doesn’t cause a side effect is:
console.log(math.max(2,4));
This will not cause a side effect even though a function was used. Its function purpose math.max is to takes any amount of number
arguments and gives back the greatest. This is a value.

What is control flow?

  1. What is meant by control flow in programming code is read like a story. The code is read from Top to Bottom. When the programme see more then 1 action to execute it will work its way down.

What is conditional execution? & What kind of keyword do you need to use to invoke conditional execution?

9/10. A conditional execution is used when you are using the “if” function. Best example i can think of is that, the web site has age restriction and user has to interact with the web page by entering there age. The “if” function is were this comes in. Your writing in code “if” there over 21 they can access the website, “if” they are not then redirect them to this code. where most likely it will show a web page saying you can access this site.

1 Like

An expression is a fragment of code that produces a value.

A binding is text that allows the script to catch and hold values.

The environment is the collection of bindings and their values that exist at a given time.

A function is a piece of programming wrapped in a value.

alert(“Now Entering Rekt City”)

Side effects are changes in the script that affect all statements that come after it.

prompt("Welcome To Rekt City, Please Enter Your Private Keys")

console.log(11-6)
`> 5`


Control flow is the order in which statements are read, from top to bottom.

Conditional execution is when the control flow is not straight forward, when there are circumstances in which “if” is used and where certain paths will be followed only “if” certain values are met.

if, else, else if

1 Like