Binding, Functions and Control Flow - Reading Assignment

5. Give an example of a function.

Hello sir, this is not an example of a function, that is just a binding, you probably mean something like:

//defining variables and bindings on them
var a; //only defined to be used on a function
var b = 1;
var c = 2;

//this is a function example
function exampleName(){
 //binding a value to "a"
 a = b+c;
 //return "a" with a new value, side effect
 return a;
}

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

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

Carlos Z.

2 Likes

Excellent answer sir! really well documented! keep it like that please! :muscle:

Carlos Z.

Excellent answer sir! really well documented! keep it like that please! :muscle:

Carlos Z.

What is an expression?

  • A fragment of code that produces a value is called an expression.
  • Every value that is written literally (such as 22 or “psychoanalysis”) is an expression.
  • An expression between parentheses is also an expression, as is a binary operator applied to two expressions or a unary operator applied to one.

What is a binding?

  • 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 binding.
  • The previous statement creates a binding called caught and uses it to grab hold of the number 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 function is a piece of program wrapped in a value.

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”);
    image

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.

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

  • The function Math.max takes any amount of number arguments and gives back the greatest.

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

// → 4

  • Math.min, which is the opposite of Math.max, is used as part of a plus expression to return a value.

console.log(Math.min(2, 4) + 100);

// → 102

What is control flow?

  • When your program contains more than one statement, the statements are executed as if they are a story, from top to bottom.

What is conditional execution?

  • Not all programs are straight roads. For example, we may want to create a branching road where the program takes the proper branch based on the situation. 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.
  • For example.

let theNumber = Number(prompt(“Pick a number”));

if (!Number.isNaN(theNumber)) {

console.log("Your number is the square root of " +

theNumber * theNumber);

}

1 Like

Excellent answer sir! really well documented! keep it like that please! :muscle:

Carlos Z.

  1. What is an expression?
    An expression is a fragment of a code that gives a value. a,b-expressions, a*b a statement.
  2. What is a binding?
    A bindings are like tentacles. they grasp information and two bindings can point to the same value.
  3. What is an environment?
    Its a collection of bindings and values that are constant.
  4. What is a function?
    A function is a piece of program wrapped in a value.
  5. Give an example of a function.
    alert(“here you are”);
  6. What is a side effect?
    A side effect is a function which produces an expression and returns that value.
  7. Give an example of a function that produces a side effect and another function that produces a value.
    alert(“side effect”)
    console.log(2+4); - value
  8. What is control flow?
    Its executing more than one statement from top to bottom in the programm.
  9. What is conditional execution?
    its a program that has more than one statement
  10. What kind of keyword do you need to use to invoke conditional execution?
    if
1 Like

Cheers Jon! Thanks for the clarification. :fist_right:

1 Like

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

What is a binding?
or a variable is used to catch and hold values

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

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

Give an example of a function.
function countApples (Alice,Bob) {
return (Alice + Bob);
}

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

Give an example of a function that produces a side effect and another function that produces a value.
var textToShow = “hello world”;
alert(textToShow);

console.log (2+4)

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?
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

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. Single values are expressions, and operators applied to values are an expression.
  1. What is a binding?
  • A special word (keyword) let, var, const; followed with a tag (any word except keywords) and attaches to a value.
  1. What is an environment?
  • A collection of bindings and their values that exist at a given time.
  1. What is a function?
  • A piece of program wrapped in a value. A function can be given parameters and do something with them.
  1. Give an example of a function.
function sum(num1, num2) {
 return num1 + num2
}

sum(4, 8)

12
  1. What is a side effect?
  • Showing a dialog box or writing text to the screen.
prompt("Enter passcode");

  1. Give an example of a function that produces a side effect and another function that produces a value.
  • A function that produces a value
 sum(4, 8)

 12
  • A function that produces a side effect.
prompt("Enter passcode");

  1. What is control flow?
  • A set of statements, executed from top to bottem.
  1. What is conditional execution?
  • A set of code that has multiple paths the program can take.
  1. What kind of keyword do you need to use to invoke conditional execution?
  • if
1 Like
  • What is an expression?
    -A fragment of code that produces a value is called an expression

  • What is a binding?
    -Bindings are used to catch and hold values. It’s what the computer uses to remember things and keep the program in an internal state.

  • 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 that can be applied to run a wrapped program.

*** Give an example of a function.**
alert(“I am him for real tho”)

*** What is a side effect?**
A side effect is a type of action that is performed in an environment of which the value result is displayed

  • Give an example of a function that produces a side effect and another function that produces a value.
    prompt(“enter your name”)
    console.log(Math.max(2,6))
    // 6

  • What is control flow?

  • The control flow is a story like approach of how the code of the program is executed
  • What is conditional execution?
    Conditional execution mean that the code of the program will only executed if there is a preexisting condition met/trigger
  • What kind of keyword do you need to use to invoke conditional execution?
    if, eise if, switch, else
1 Like
  1. Code that produces a value
  2. It holds value
  3. Pre set bindings of values
  4. A program wrapped in a value
  5. alert()
  6. Effects that affect coming statements
  7. prompt()
  8. The order of code execution
  9. Allows programs to behave differently depending on input
  10. if, else
1 Like
  1. What is an expression?
    A fragment of code that produces a value.

  2. What is a binding?
    Catches and holds values and can be used multiple times.

  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.
    alert(“this is an example of a function”);

  6. What is a side effect?
    Something only if it affects the world.

  7. Examples of functions:
    Function producing value
    let twenty = 20;
    console.log( twenty * twenty);

Function producing side effect
let mood = “happy”;
console.log(mood);
or
alert(“this creates a side effect as well”);

  1. What is control flow?
    Where the program takes the paper branch based on the situation at hand.

  2. What is conditional execution?
    Where the program takes the paper branch based on the situation at hand.

  3. Keyword for invoking conditional execution?
    if

1 Like
  1. What is an expression?
    It’s a statement code that gives a result on that expression.

  2. What is a binding?
    It’s a function function is happens using Bind () method. by this method, we can bind an object to a common function, so that the function gives different result when its need. otherwise it gives the same result or gives an error while the code is executing.

  3. What is an environment?
    Storage space that maps variables name to values.

  4. What is a function?
    Is a program that executes and returns a value, it allows to reuse the code instead of writing as many times you need it.

  5. Give an example of a function.
    console.log(name, dob, emal)

  6. What is a side effect?
    Modifying values, variables outside it scope.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    alert("Hello, World!)

  8. What is control flow?
    it’s the order that the computer executes a statements in a script.

  9. What is conditional execution?
    Instructions on how the program will behave depending on conditions.

  10. What kind of keyword do you need to use to invoke conditional execution?
    The keyword is If().

1 Like

1 - What is an expression?

A segment of code, when executed, that produces an artifact, termed a value, is called an expression.
The value produced can be a number, boolean, string or an object.

2 - What is a binding?

A binding is sometimes called a variable is a label that holds a value.
In some contexts it is called a pointer.

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 program wrapped in a value.
I think this may be a pointer to a function.

5 - Give an example of a function.

alert(“Ivan on Tech is where the winners are!”);

6 - What is a side effect?

A side effects is the resulting evidence as a consequence of the execution of a function.
No return value is produced.

ex: alert(“Hello”);

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

side effect: alert(“Hello”);

value: document.getElementById(‘page-heading’);

8 - What is control flow?

The incremental execution of each line of code in sequence is a linear control flow

9 - What is conditional execution?

An example of a conditional execution, is when a program deviates from its default main path, to go down a branching road
branching road. The branch road is taken by the program due to the result of a conditional execution code.

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

The key words are the following:

	if 
	else if
	else
1 Like

An expression is a piece of code that produces a value, which could be a simple string or number, literally, or something more complex like a nested set of expressions.

Bindings are ways to grasp values. Reserved words ‘var’, ‘let’, or ‘const’ will allow you to assign values to a placeholder that you get to name. The construct would be ‘keyword placeholder-name = some value’, for example, var firstName = ‘Ivan’. Placeholder names cannot begin with a number, nor can they be any of the reserved keywords of javascript, they can contain ‘$’ or ‘_’ but no other special character, and they should be descriptive - it makes reading code and debugging oh such much easier. Var and let are used to assign variables while const is used to assign constants that cannot be reassigned in the same program.

The environment is the sum of all bindings and their values. This would include functions that exist in javascript to interact with a browser. An interactive webpage environment changes as the user interacts with the page, so environments aren’t static. An example of a function that is always present in a javascript environment is Number.isNaN, which tests whether the argument passed to it is “not a number”.

Functions are bits of code wrapped by values. To construct a function, take a bit of code and wrap it in curly braces { }, making sure each line of code ends with a semi-colon. Precede the { } with the reserved keyword ‘function’ followed by a name that you select for your function, followed by opening and closing parentheses, ( ). Inside the parentheses is the magic spot! That’s where we can put a variable or other values to pass to the function. Getting a function to run is called invoking, calling or applying the function. Invoke a function by calling its name and perhaps passing a couple of values. Calling a function will return some value that was created by the wrapped bit of code.

For example, a function called ‘waterGarden’ could be used to alert someone to do that chore when the predicted high temperature for the day is 85F or higher. It might look like:

function waterGarden (highTemp) {
let chores = null;
if (highTemp > 85) {
chores = ‘Over 85 today – Water Garden This Morning!’;
}
else {
chores = ‘Cool day – Walk The Dog!’;
}
return chores;
}

The function would be called like this: waterGarden(87) or waterGarden(75) and we can output the returned value of chores using console.log, another function always available by default.

console.log(waterGarden(87));
console.log(waterGarden(75));

Functions return values but can have side effects like presenting output on a screen.

Control flow refers to the order in which lines of code are executed. A program is read from the top down line by line unless a conditional expression diverts the flow. Certain reserved keywords, like ‘if’, ‘else if’, ‘else’, and ‘break’ change the flow based on some evaluated condition.

1 Like

1: An expression is a piece of code that produces a value

2: A binding is used in JavaScript to catch and hold values, usually led by the keyword “let”

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

5: alert(“go to bed in 5”);

6: A side effect can be a dialog box that has been produced by a function.

7: alert(“side effects may occur”)
console.log(Math.max(2,4));

8: Control flow is that when a program is executed it goes from the top statement through to the bottom statement in order.

9: Conditional execution is when we want the program to only act if certain factors are at play.

10: “if”

1 Like

Excellent answer sir! really well documented! keep it like that please! :muscle:

Carlos Z.

Remember you can use the “Preformatted Text” Button to encapsulate any kind of code you want to show.


I am a happy Preformatted Text box, please use me wisely!

Carlos Z.

1 Like

Thanks Carlos! I just learned about the ‘</>’ button but obviously will have to use it a few more times to remember to use it, if that makes sense. :+1:

1 Like
  1. A fragment of code that produces a value.

  2. A binding catches and holds a value.

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

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

  5. function multi(a, b) {return a * b;}

  6. A side effect affects the statements that come after it.

a) let name = "Bernd";
b) Math.max(11, 23)

  1. Statements are executed from top to bottom.

  2. A branching road, where a given path is executed based on the present situation.

  3. Conditional executions use the keyword if

1 Like

Hi @angieww,

Mostly OK, but some clarifications needed…

KInd of … an expression is any piece of code that evaluates to (produces) a value.

Not sure where you’ve got this idea from… a binding is not a function, but a function can be assigned to a binding.

Basically, a binding (or variable) is any value or expression which has been assigned to a name (effectively labelled) in order for it to be stored in the computer’s memory, and then accessed and reused by the program whenever required. A variable is defined using the keyword let , const , or var , followed by its chosen name. The value is assigned (tied/bound) to the variable’s name using = (the assignment operator ) e.g.

      let myVariable = (a + b) / 100;

Yes :+1: …that’s an example of a function that produces a side effect: the side effect is the pop-up alert window that appears in the browser when the function is called.

Math.max(5, 3);    // => 5
// an example of a function that produces a value (5).
1 Like