Binding, Functions and Control Flow - Reading Assignment

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

What is a binding?
A binding is a variable, it holds the value of an expression.

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

What is a function?
A function is a piece of program wrapped in value where such value can be applied in order to run the program.

Give an example of a function.

alert(“bitcoin to the moon”);

What is a side effect?
A side effect is any application state change that is observable outside the called function other than its return value. Side effects include:
Modifying any external variable or object property
Logging to the console
Writing to the screen
Writing to a file
Writing to the network
Triggering any external process
Calling any other functions with side-effects

Give an example of a function that produces a side effect and another function that produces a value.
Side effect
alert(“when moon Ivan”);

Value
console.log(Math.max(3, 6));

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

What is conditional execution?
Statements are executed depending on a condition.

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

1 Like

[quote=“ivan, post:1, topic:3069”]

  • What is an expression?
    Any fragment of code that produces a value.
  • What is a binding?
    It is the way that the computer will remember a value. We use the verb “let” to define a value so that the computer knows what we mean next time we mention the same binding.
  • 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. Such values can be applied
    in order to run the wrapped program.
  • Give an example of a function.
    prompt(“Enter passcode”)
  • What is a side effect?
    Side effects are changes performed by a program which cause no observable change on the world. They just display a value and disappear.
  • Give an example of a function that produces a side effect and another function that produces a value.
  • What is control flow?
    Control flow is the order in which our codes are executed. We set it up in a way that the system would follow the sequence.
  • What is conditional execution?
    Conditional exec is dependent on what happens. If one thing happens, then the system would give one result. If another happens, then it would give a different result.
  • What kind of keyword do you need to use to invoke conditional execution?
    if and else
1 Like
  • What is an expression?

Expression is a fragment of code that produces a value.

  • What is a binding?

Binding catching and hold a value which was previously set.
Key words let var const indicates that this sentence is going to define a binding.

  • What is an environment?

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

  • What is a function?

A function is a piece of program that performs specific task.

  • Give an example of a function.
let theName = ("Lukasz");
let greatings =("Hello " + theName);
console.log(greatings);
  • What is a side effect?

Is a effect of change which affects the internal state of machine and statement that come after it.

  • Give an example of a function that produces a side effect and another function that produces a value.
prompt("ABCD"); 

console.log(Math.max(5, 10));

  • What is control flow?

Control flow are statements inside your source files are generally executed from top to bottom, in the order that they appear.

  • What is conditional execution?

We using it when we want some code to be executed if, and only if, a certain statement is true.

  • What kind of keyword do you need to use to invoke conditional execution?
    if or else
1 Like

What is an expression?

A fragment of code that produces a value is called anexpression.
Anything that produces a value is an expression in JavaScript. Expressions must have semi-colon at the end.

What is a binding?

This is how a program remember things. To catch and hold values, JavaScript provides a thing called a binding, or variable:

let caught = 5 * 5;

The special word (keyword) let indicates that this sentence is going to define a binding. This statement creates a binding called caught and uses it to grab hold of the number that is produced by multiplying 5 by 5.

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 lot of the values provided in the default environment have the type function. A function is a piace of program wrapped in a value.

Give an example of a function.

document.write("Start slow, let yourself snap!"); *

prints the string encapsulated by “” symbols.

* JavaScript Cheat Sheet, Outputting Data, document.write() — Write directly to the HTML document

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.

  1. alert();

  2. Math.round(3.14159265358)

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, like a flow. Once we define a variable then later at next lines we put it in a function to process it later. Engines read our commands in lines from top to bottom in a flow.

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?

Conditional execution is created with the if keyword in JavaScript.

1 Like

Hi @Amri2020,

There was some kind of formatting problem with your message/post to me. All I see in the forum is:

Just repost it, or let me know if I can help you with anything :slightly_smiling_face:

1 Like
  1. a value
  2. a connection to a value with keywords like: var, let or const
  3. collection of bindings and values
  4. a piece of program wrapped in a value
  5. prompt(“Enter passcode”); alert(“invest in your knowledge”);
  6. an action produced by a function, like a popup window
  7. a) same like point 5
    b) console.log(Math.max(2, 4) + 100); 20+2
  8. the code runs in the order from first to last like a story
  9. if the control flow jumps to an other point of statement at a special condition
  10. by using the keywords “if” and “else”
1 Like
  1. What is an expression?
    A fragment of code that produces a value.

  2. What is a binding?
    It “binds” a name to an expression, either using let, or var, enabling use of the expression simply by using the name.

  3. What is an environment?
    The collection of bindings and their 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.
    console.log()

  6. What is a side effect?
    Something returned by calling a function that is not just a pure value, such as printing text, showing an alert, or prompting for input.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    Side effect-producing function: alert(“hello”);
    Value-producing function: var a = “hello”;

  8. What is control flow?
    It is the order in which functions are executed. This will be in a straight line from top to bottom, unless conditional functions are present.

  9. What is conditional execution?
    It is when code is executed only when a certain condition exists.

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

1 Like
  1. An expression is any piece of code that resolves to a value. The value may be a number, a string or a logical value.
  2. A binding is a stored value which it can be used later. Example: let fire = 1+1. The variable fire is now has a stored value of 1+1
    3.An environment is a collection of bindings and their values that exist at a given time.
  3. A function is is an expression wrapped in a value. It can be executed by calling it.
  4. Example function:
    alert(“Hello”);
  5. A side effect is any expression or function that displays or otherwise changes the string or value on the web page, basically if the program changes visibly it is a side effect.
  6. Example of function that produces a side effect and another function that produces a value:
    side effect: console.log(a);
    value: let a = 1;
  7. A control flow ensures that statements are executed in proper order
  8. A conditional execution is where a program can execute different statements depending on the situation presented
  9. The If Then Statement would be an example of conditional execution.
1 Like

What is an expression?

A fragment of code that produces a value.

What is a binding?

Binding allows a program to maintain an internal state, program values have to be immediately used or will dissipate.

JavaScript provides binding/variable to catch/hold those values via using keywords

let or var (var is short for variable)

JavaScript has up to 44 Binding names (function/void etc used commonly) you can make your own Binding name.

What is an environment?

When a program starts up, it’s environment contains bindings to interact with surrounding systems.

What is a function?

A function is a piece of program wrapped in a value; a block of code designed to perform a particular task.

Give an example of a function.

function myFunction(p1, p2) {

return p1 * p2;

}

What is a side effect?

Think of a side effect that does two things at once: Example

var i = 1;

var j = i++;

A “side effect” is any effect than that return value.

“Side effects” are interactions with the outside world from inside of the function.

The challenge with side effects is that they make functions harder to reason about to reuse, it’s much easier to reason and reuse functions that are as close to “pure functions” since they tend to “do one thing well”.

“Pure functions” have no side effects.

“Pure functions” are when any given input will always produce the same output. The return value is always the same

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

var i = 1;

var j = i++;

function myFunction(p1, p2) {
return p1 * p2; // The function returns the product of p1 and p2
}

What is control flow?

The order which statements are executed. From top to bottom like a story thou using keyword ( if ) can redirect the flow.

What is conditional execution?

Is to create a branching road, where the program takes the proper branch based on the situation at hand.

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

Keywords (else and if) redirect the flow.

1 Like

What is an expression?

  • fragment of code that produces a value is called an expression ( 22,“hallo” …)

What is a binding?

  • it is a reference point like var and constant is so you can use this ‘binding’ to access the values

What is an environment?

  • environment can be see as defined settings, collections of bindings

What is a function?

  • A function is a piece of program wrapped in a value

Give an example of a function.

  • prompt is a function ==> prompt(“Enter passcode”);

What is a side effect?

  • Showing a dialog box or writing text to the screen is a side effect.
  • functions that produce directly a value don’t need to have a side effect to be usefull

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

  • side effect function : prompt("Enter passcode (window appears as side effect) ");

What is control flow?

  • 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

What is conditional execution?

  • conditional execution is when the program takes the proper branch based on the situation at hand

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

  • the IF statement to test a condition
1 Like
  1. An expression is a piece of code that returns a value ((3+2), 15, “Book”)

  2. Binding is the act of pointing a variable to a value. It allows your program to have memory and be able to reference values later.

  3. An environment is the existing set of variables and their values at a given time. The environment can change from one page to another.

  4. A function is a piece of code that performs some sort of work on the values (arguments) that are supplied to it. When the function is invoked, it takes the given arguments and produces a new value.

  5. Math.max()

  6. A side effect is a change to something outside of the duties of the function just returning a value.

  7. alert() produces a side effect of showing a dialog box

Math.max returns a value (whichever number is bigger)

  1. Control flow is the order in which statements in a program are executed. This can be modified with loops and conditions.

  2. Conditional execution is only executing certain statements within a program if certain conditions are met.

  3. if, else, while

1 Like
  1. a fragment of code that produces a value
  2. a statement to catch and hold values
  3. The collection of bindings and their values that exist at a given time
  4. a piece of program wrapped in a value
  5. prompt
  6. a function that shows a dialogue box or writes text to the screen
  7. side effect: prompt, produces value: Math.max
  8. the order in which statements are executed
  9. code is executed only if a condition is met
  10. if
1 Like
  1. What is an expression?

A fragment of code that produces a value. Example, x=1+2

  1. What is a binding?

In the example x=1+2, x is the binding, and it is being attached to the value 3 or (1+2).

  1. What is an environment?

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

  1. What is a function?

A function is a piece of program wrapped in a value. These values can be applied to run pre-set programs on other values.

  1. Give an example of a function.

Prompt() is a function in browsers that opens a text box and displays a title.

  1. What is a side effect?

A side effect is an outcome of a function other than returning a value, such as creating a dialog box.

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

Mathematical functions such as min() and max() return values without producing any side effects. Functions such as prompt() or console.log() create a change in the world, a side effect other than returning a value.

  1. What is control flow?

Control flow is the order in which statements are executed, In JS, this is from top to bottom ( like how a human reads English text).

  1. What is conditional execution?

Code being executed if, and only if, a certain condition holds.

  1. What kind of keyword do you need to use to invoke conditional execution? if( condition ){ statement }

while( condition ){ statement }

do{ statement }( condition )

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

  • What is a binding?
    A: Bindings catch and hold values. They are like tentacles, rather than boxes. They do not contain values; they grasp them.

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

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

  • Give an example of a function.
    A: console.log

  • What is a side effect?
    A: 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.
    A: The function prompt(“Enter passcode”); produces a side effect. The function Math.max produces a value.

  • What is control flow?
    A: 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?
    A: Where the program takes the proper branch based on the
    situation at hand, IF certain conditions are met.

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

1 Like
  1. AN expression is a piece of code that creates a value
  2. A binding is something that catches values.
  3. An environment is a colleciton of of bindings and their values.
  4. A function is a piece of program wrapped in a value.
  5. A function could look like => prompt(“enter passcode”)
  6. A side effect is essentially writing script to the screen.
  7. Side effect example = prompt(“enter passcode”) vs value example console.log( 2* 2). A side effect is similar to an action vs the value which is a result diplayed by a function via a return.
  8. When your code contains many statements, the statements will be executed inline with the order of the control flow.
  9. Conditional execution is creating various alternate ways for the code to return a value.
  10. Can use keywords such as “if” or “else”
1 Like

1.What is an expression?
A piece of code that produces a value is called an expression
2.What is a binding?
Variables are used to hold values, such as in “let x = 5”, which means x has binding to “5” (in this case)
The words var and const are also used to create bindings,
3.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.
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.
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”);
6.What is a side effect?
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. Functions may
also produce values, in which case they don’t need to have a side effect to
be useful
7.Give an example of a function that produces a side effect and another function that produces a value.
prompt(“Hello World”); function add (let a, let b) {return a+b;}
8.What is control flow?
Control flow means, that the statements in a program are executed from top to bottom.
9.What is conditional execution?
Conditional execution happens, by using conditions like if, while, do in a program. Conditions can interupt
10.What kind of keyword do you need to use to invoke conditional execution?
if

1 Like
  1. An expression consist of variables and operators and is contstructed in a way to output a value.

  2. A binding is like metyphorical envelope used to hold values in memory

  3. It’s a collection of binding and thier variables at that point in time

  4. Its an axpression that can be called and when given inputs will provide an output

  5. console.log(“Hello”)

  6. A prompt or screen display is a side effect

  7. prompt(“hello”) and console.log(“hello”)

  8. The order in which code is executed, Top to bottom and left to right

  9. When a logical operator using an If statement determines which branch code to execute.

  10. The key word is IF

1 Like

Excellent answers sir, well documented! Please keep them like that :muscle:

Carlos Z.

Makes sense :upside_down_face:Thanks @jon_m!

1 Like
  1. An expression is a fragment of code that produces a value. Every value that is written literally is an expression. If a is an expression and b is an expression then a+b; is a statement.

  2. A binding is a way to store values. By using the keyword let we can define a variable, for example, let caught = 5*5; so when we enter the word caught we should get a value of 25.

  3. An 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. Such values can be applied in order to run the wrapped program.

  5. In a browser environment, the binding prompt holds a function that shows a dialog box asking for user input, for example;

prompt (“enter password”);

  1. Writing text to a screen or showing a dialog box is known as a side effect. A lot of functions are useful because of the side effects they produce. Functions which also produce values don’t need to have a side effect to be useful.

  2. prompt (“enter username”); is a function that produces a side effect in the form of a dialog box.
    console.log(Math.max(2, 4)); is a function that will return a value that is 4.

  3. Control flow relates to the order in which statements in a program are executed. If a program contains one or more statements then they are executed as if they are a story, from top to bottom.

  4. Sometimes within a program we may want some code to be executed if, and only if, a certain condition holds. This creates a branching road or alternate path and is known as a conditional execution.

  5. if and else.

1 Like