Binding, Functions and Control Flow - Reading Assignment

Binding, Functions and Control Flow.

  1. Expression is a value or a collection of values. Expression can represent numbers, texts or functions.
  2. Binding is a function that links two expressions together.
  3. Enviroment is a collection of expressions and their bindings in some program.
  4. It is a special expression that when written with other value, it can ouput something.
  5. Alert(“hello world”);
  6. Side effect is when function outputs something that is not evident from the function itself.
  7. Var a = 2, Var b = 3, console.log (a * b); This produces a side effect
    Allert(“value”); This produces a value
  8. Control flow is a way in which the program is executed. The program is executed like a book story, from top to bottom.
  9. The function executes in special situations based on the conditions you set.
  10. If , Else
1 Like
  1. What is an expression?

° Every value written literally or a fragment of code that produces a value, is an expression.

  1. What is a binding?

° A binding catches and holds the meaning of a given value, you could also say javascript uses bindings to remember given values !
After the bindings have been defined they can be used in expressions.

  1. What is an environment?

° This is the collection of bindings and their values at any given time in a program, they are part of the language standard, these bindings provide ways to interact with the surrounding system.

  1. What is a function?

° Its a piece of program wrapped in a value. For example ; in a browser environment the the binding prompt holds a function that shows a little dialog box asking for user input .

  1. Give an example of a function.

° In a browser environment the the binding prompt holds a function that shows a little dialog box asking for user input .
prompt (“Enter password”)

  1. What is a side effect?

° A function which produces an expression and returns that value . For example showing text to the screen is a side effect

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

° alert (" Hello world is an example of a side effect ")
° console.log (Math.max( 2, 4 ));
-// 4

  1. What is control flow?

° This is the execution of statements from top to bottom , when more than one statement is written.

  1. What is conditional execution?

° This is the execution of statements if and only if certain conditions are achieved ,only then can the statement be executed by the program .

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

° The keyword needed is; if

2 Likes

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

What is a binding?
A binding is used to catch and hold variables. It uses the ‘let’ statement (eg let caught = 5 * 5;)

What is an environment?
The collection of bindings and values at any one time is called the ‘environment’

What is a function?

A function is a piece of program wrapped in a value. You call a function by putting parenthesis after an expression 	that produces a function value. The values between the parenthesis are given to the program inside the function. 	Values are passed into the function for processing. This creates reusable code blocks.

Give an example of a function.

// function area(a,b){

// var c = a*b   
// return c   
// }
	
//area(4,5)
//20

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 (e.g., a global variable) eg 		logging to the console, writing to the screen etc. According to the rules of functional programming, functions are 	not allowed to modify any states outside of the function. If the function modifies a state, intentionally or 		unintentionally, this is considered a side effect because it breaks the tenets of functional programming.

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

This function returns a value:

// function area(a,b){

// var c = a*b   
// return c   
// }
	
//area(4,5)
//20	
...................................

This code has a side effect. The example returns nothing. It relies on shared state to do its job by 	incrementing a variable outside of its own scope.

//function addition();
//let x = 2;

//const add = (y) => {
//x += y;
//};

//add(4); // x === 6 (the first time, 10 the second time etc.)

What is control flow?
Control flow allows the programmer to break out of the conventional sequential step by step program flow, allowing the code to branch off into sub sets of code as required.

What is conditional execution?
A program has numerous blocks of code. In conditional execution, a certain block of code is only executed IF it meets certain conditions. If the condition is not met the block is not executed.

What kind of keyword do you need to use to invoke conditional execution?
an IF statement eg

	if (age < 17);
		do this block
	elseif (age => 17);
		do this block
1 Like
  1. An expression is a fragment of code that produces a value.

  2. A Binding is to catch and hold the meaning of values.

  3. Collection of bindings and their values that exist at any given time.

  4. A piece of program wrapped in a value.

  5. Prompt, alert

  6. Is when function changes the that of something within a statement or outside or it.

  7. Prompt (Enter passcode") is a side effect

console.log(Math.max(4,6));
//→ 6 is a value

  1. The execution of the program, form top to bottom as if a story.

  2. Is creating an alternative outcome based on previous inputs depending if something happens or does not.

  3. If, and only if.

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

  2. What is a binding?
    It is used to catch and hold variables. To assign meaning/variable to something else.

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

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

  5. Give an example of a function.
    function helloFunction(){
    alert(“Hello Ivan on Tech Academy!”);
    }
    helloFunction();

  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.
    Side effect function example:
    function helloFunction(){
    alert(“This is a side effect, I think”);
    }
    helloFunction();

Function that produces a value example:
var a = 5
var b= 10
console.log(a + b);

  1. What is control flow?
    A program with more that one statement is executed from top to bottom.

  2. What is conditional execution?
    A conditional execution is created with the if keyword. There are conditions that must be met for the program to produce an output or the output is different depending on the conditional statements in the program.

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

1 Like
  1. Any piece of code that produces a value is an expression
  2. Binding attaches a variable or function name the this keyword to create an execution context.
  3. An environment is the collection of variables and values that exist at any given time. Variables of the type function also exist in the standard environment.
  4. A function is a piece of program wrapped in a value that generally does something useful.
  5. An example of a function that produces a side effect is the alert function.
  6. An example of a function that produces a value is the Math.min function
  7. Control flow is a way to execute the statements in your program when a particular condition is met.
    8, Conditional execution uses conditional expressions to control execution
  8. keywords such as if, else, and while invoke conditional execution
1 Like
  1. A fragment of code that produces a value

  2. An entitled piece of information that stores value, also referred to as a variable

  3. A collection of variables and their values at a given point in time

  4. a piece of code designed to perform a particular task. A function is executed when something invokes it

  5. var a = compute(9,5)
    console.log(a)

  6. A function that produces an observable change in the state of a program

  7. alert(“side effect example”)
    console.log(a);

  8. executing a program from top to bottom

  9. when certain program code is only executed under a specific condition

  10. “if”

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

  2. What is a binding?
    A binding , or variable, is something JavaScript provides to catch and hold values.

  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 a program wrapped in a value.

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

  6. What is a side effect?
    When a statement is used to change the internal state of the machine in a way the will affect the statements coming after it. That is a side effect.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    E.g. produce side effect:
    alert (“Hello world”);

E.g. produce a value:
console.log(1+2);

  1. 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. Sounds like a flow of control.

  2. What is conditional execution?
    Not all programs take a straight road of execution. Sometime at a point there are several directions we created for the program to execute based on the situation. That is conditional execution.

  3. 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 produces a value is called an expression.

  1. What is a binding?

A binding or variable is a tag attached to a value and it is kept in the memory of the program.

  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.

  1. Give an example of a function.

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

  1. 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.

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

Side effect:
alert(“Hello World”);

Value:
var num1 = 10
var num2 = 20

console.log(num1 + num2);
// → 30

  1. What is control flow?

Control flow in JavaScript is how your computer runs code from top to bottom. It starts from the first line and ends at the last line, unless it hits any statement that changes the control flow of the program such as loops, conditionals, or functions.

  1. 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.

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

‘if’ statement

1 Like

1)What is an expression?
An expression is a fragment of code that produces a value.
2)What is a binding?
A binding declare and holds value of an expression.
3)What is an environment?
A collection of bindings ad their values that exist at a give time.
4)What is a function?
A function is a piece of program wrapped in a value.
5)Give an example of a function.
prompt(“give passcode”);
prompt being the function
6)What is a side effect?
showing a dialog box or writing text to a screen is a side effect of the comand
7)Give an example of a function that produces a side effect and another function that produces a value.
prompt(“Enter Password”);
console.log(Math.max(2,4));

8)What is control flow?
When your program contains more than one statement, the statements are executed from top to bottom.
9)What is conditional execution?
Not all programs are straight roads some are created with branching roads where the program takes proper branch based on the condition at the time.
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. Binding is a function that sets what output is given when a keyword of a function or method is invoked.
  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 binding
  5. Example:
    function CountCars(RyansCars,FredsCars){
    return RyansCars + FredsCars
    }
  6. A side effect is a statement that changes the world or the internal state of the machine in a way that affects the statements that come after.
  7. Side Effect Function: SetTimeout()
    Value: avg(a,b)
  8. A control flow is the execution of statements from top to bottom
  9. A conditional execution is a program that allows for different output values depending on what the input value is
  10. if is the keyword to invoke conditional execution.
1 Like
  1. What is an expression?

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

  1. What is a binding?

To catch and hold values, JavaScript provides a thing called a binding, or a variable.

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

  1. Give an example of a function.

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

  1. What is a side effect?

A statement stands on its own, so it amounts to something only if it affects the world. For instance, it could display something on the screen which 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.

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

Side effect function:

alert(“Hello World”);

Value Function:

Value:
var num1 = 10
var num2 = 10

console.log(num1 + num2);
// → 20

  1. What is control flow?

In Javascript, when a program contains more than one statement, the statements are executed as if they are a story, from top to bottom.

  1. 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

  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 is called an expression。
2.To catch and hold values, JavaScript provides a thing called a
binding, or variable:The special word (keyword) let indicates
that this sentence is going to define a binding。
3.The collection of bindings and their values that exist at a given time is called
the environment.
4.A lot of the values provided in the default environment have the type 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.For example, in a browser environment,
the binding prompt holds a function that shows a little dialog box asking for
user input.
6. 1. Side effect is a statement result that changes something that affects the program
7.isNan() would produce a value, Number() would produce a side effect by converting a value to a number
8,It is the direction of execution of code in JavaScript which happens in a top down approach.
9.Conditional Execution is a branch in the control flow’s execution, where JavaScript picks a branch depending if the conditions that are present.
10. * Use

if
to specify a block of code to be executed, if a specified condition is true

  • Use

else
to specify a block of code to be executed, if the same condition is false

1 Like
  1. What is an expression?
    A piece of code that produces value. Example : “ABC”
  2. What is a binding?
    Binding or a variable is a storage for data in Javascript.
  3. What is an environment?
    It is a collection of all the bindings/variables and their values that exist at any given time.
  4. What is a function?
    A piece of program writen in a block of code that is wrapped in a value.
  5. Give an example of a function.
    console.log ()
  6. What is a side effect?
    It is any state change that is observable outside the called function other than its return value. For example it shows a dialog box or writes text to a screen.
  7. Give an example of a function that produces a side effect and another function that produces a value.
    Side effect:
    window.alert(“What is your name?”);

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

  1. What is control flow?
    Execution of a program from top to bottom, the order in which the code should execute.
  2. What is conditional execution?
    A certain condition needs to be met in order for execution.
  3. What kind of keyword do you need to use to invoke conditional execution?
    if/else statements
1 Like

Expression = a fragment of code that produces/returns a value.

Binding = function that catches en holds values

Environment = collection of bindings and their values that exist at a given time

Function = piece of program wrapped in a value designed to perform a specific task.

An example of a function is a prompt in a browser environment.

Side effect = showing a dialog box, writing text on a screen, changes executed,

Function causing side effect = prompt which leads to showing a box on the screen

Function causing value = mathematical functions that add up or substract

Order in which the program is executed (e.g. conditional, while).

Keyword for conditional = if

1 Like
  1. What is an expression?

A piece of code that produces a value.

  1. What is a binding?

A binding or variable is a construct that has been assigned a value, i.e. it holds the assigned value. Bindings can hold different values if they are assigned to different values throughout the code but there are also constant bindings that hold the same value as long as the binding exists.

  1. What is an environment?

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

  1. What is a function?

A function is a piece of code that takes in arguments and generates value/output based on these arguments. A function needs to be defined once and then can be invoked over and over again. Usually, the range of valid arguments for a function is limited (e.g. only numerical values).

  1. Give an example of a function?

The following function takes in two numerical values as arguments and returns the sum of both arguments as output:

function numsum(num1, num2) {

return num1 + num2;

}

  1. What is a side effect?

A side effect is any effect caused by a function that affects something outside the function’s boundaries. Printing something on the screen or opening a dialogue box would be a side effect (effect is not within the boundaries of the function).

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

Function producing a value (see answer #5): numsum(2, 8);
This function returns the numerical value 10 (no side effect).

Function producing a side effect: console.log(numsum(2, 8));
This function prints 10 on the screen, which is a side effect, and returns undefined.

Question: From the examples provided in the book Eloquent JavaScript on p. 27 I understand that the author says that the following function returns a value: console.log(Math.max(2, 4))
Technically speaking, isn’t it the case that this function only prints the value and returns undefined? Or am I misinterpreting something?

  1. What is control flow?

Control flow is the order in which the code is executed.

  1. What is a conditional execution?

A particular piece of code is executed if, and only if, a certain condition holds. In case the condition doesn’t hold, the code is not executed or an alternative code is executed instead.

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

The keyword for conditional execution is “if”. However, while-, do- and for-loops also run only as long as the underlying condition is true (the boolean value of the condition must be true).

1 Like
  1. An expression is a piece of code that resolves to a value.

  2. A binding is another word for a variable, which contains information inside.

  3. An environment contains all of the variables - some default and some customised - within a given program. Each page has a different environment.

  4. A function is a variable and a value, that produces a new value.

  5. alert is a function that causes a given value, e.g. “Hello” to display on the page as a pop-up.

  6. A side effect is a piece of behaviour triggered by the function, that either has real effects on the screen, or affects another part of the program.

  7. alert produces a side effect in the form of a pop-up. Math.min produces a value, in the form of the lowest value inserted into the function.

  8. The order in which we code.

  9. Conditional execution is when a particular function is executed only if another condition is met. E.g. If CurrentNum > 5, alert (“Large number”);

  10. To invoke conditional execution, one must use if and or else.

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

  2. What is a binding?
    A binding is another word for a variable, which allows the computer to store values.

  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 an expression that takes one or multiple inputs, manipulates them and gives back a certain value or values.

  5. Give an example of a function.
    function(a, b){
    return c = a + b;
    }

  6. What is a side effect?
    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.

//no side effects
function Logic(a, b){
   c = a || b;
   return c
}

//side effect
function Logic(a, b){
   c = a || b;
   alert(c);
   return c
}
  1. What is control flow?
    This is the order or path in which statements are executed.
  2. What is conditional execution?
    Execution of statements/code can depend on certain conditions. If conditions are met, this is conditional execution of the code.
  3. What kind of keyword do you need to use to invoke conditional execution?
    If, Else, While statements.
1 Like
  1. What is an expression?
    An expression is a fragment of code that produces a value.

  2. What is a binding?
    A binding or variable is a mechanism of the JavaScript language that allows the result of an expression to be captured for use in oyhr expressions later on.

  3. What is an environment?
    An environment is a collection of bindings and their values that exists at a particular point in time.

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

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

  6. What is a side effect?
    A side effect is a change to the internal state of the machine caused by a statement (including a function) that affect statements that come after it.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    Prompt() is an example of function that produces a side effect because it pops up a dialog.
    Math.max() is an example of a function that produces a value.

  8. What is control flow?
    Control flow refers to the order of statement execution in a program.

  9. What is conditional execution?
    Conditional execution is the refers to controlling the path that a program takes based on conditions that are evaluated during program execution.

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

1 Like
  1. Is a piece of code that resolves to a value.
  2. Binding is a variable. Is a piece of computer memory, containing some information inside.
  3. An environment is a set of variables and their values that exist in memory at a given time.
  4. A Function is a group of codes that be called by the program to compute a value.
  5. https://www.w3schools.com/js/js_functions.asp
  6. A side effect is a function that produces an expression and returns the value.
  7. alert(“Welcome to the bar”) has a side effect
    console.log(2+7)); produces a value
    8.Starting top to bottom, the execution flow when you have more than one statement.
  8. When using a logical operator to determine either or not to execute certain parts of the code.
  9. There is more than one but “if” is the keyword to invoke conditional execution.
1 Like