Binding, Functions and Control Flow - Reading Assignment

Hi again, @AF90!

Some excellent answers here! :+1:

Just be careful here. Anything returned to the console is a side effect, because you need to use console.log() in your program to achieve that. An example of a function that produces a value could be:

Math.min(5,9,7,20);
1 Like
  1. What is an expression?
    A fragment of code that produces a value.

  2. What is a binding?
    catching and holding values is what Javascript calls binding.For Example: @ivan owns me $100 and paid me back $20

let ivanisDebt = 100;
ivanisDebt = ivanisDebt - 20;
// ->105
  1. What is an environment?
    When you start a program the environment you see shows empty but is not empty. the backend has a collection of bindings and their values.

  2. What is a function?
    A function is a piece of program wrapped in a value. It’s like the login box that you get when login to ivanontech.com

  3. Give an example of a function.
    See 4

  4. What is a side effect?
    A dialog box or text that show up to the screen.

  5. Give an example of a function that produces a side effect and another function that produces a value.
    Side effect:
    side effect dialog box

Value:

console.log(Math.max(4, 8));
//->4
  1. What is control flow?
    You program containing more than one statement that execute a story from top to bottom.

  2. What is conditional execution?
    the keyword ‘if’ in JS creates conditional execution.
    For example showing the square of the input only if the input is actually a number.

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

if
1 Like

Q1: An expression is any fragment of code that produces a value

Q2: Binding is the process by which you would assign a keyword a value that you choose.

Q3: An environment is the collection of bindings and their values at a certain time.

Q4 :A function is a piece of program that is wrapped in a value.

Q5: prompt (“enter passcode”);

Q6: When a statement or function modifies something outside its scope it produces a side effect

Q7: side effect example
prompt(“Enter your name”);
value example
console.log(Math.max(2, 4));
it will output a value that is 4

Q8: Control Flow is the order in which the code is executed

Q9: Conditional Execution means a code will be executed if it meets a certain condition

Q10: , if else, while, loop, true/false

1 Like

5 Binding, Functions en control flow

1 What is an expression?

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

2 What is a binding?

We use bindings so we can let a program remember things (internal state). The bindings catches and hold values so they can be used later on during programming. It makes it easier for a programmer.

3 What is an environment?

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

4 What is a function?

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

5 Give an example of a function.

prompt(“Enter passcode”);

6 What is a side effect?

Changes that could change the internal state of a machine in a way that will affect the statements that come after it.

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

  • Console.log(“Enter Password”); - produces a side effect.
  • Console.log (3+4); - produces a value ‘7’

8 What is control flow?

Inputs of for example users have to pass conditions. Through the conditions you can control the input flow so you can have good results (outputs)

9 What is conditional execution?

Based on the situation the program takes the proper branch to execute code (If and only if…).

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

Here we are using the ‘if’ keyword in Javascript.

1 Like

1. What is an expression?
Small piece of code that produces a value.

2. What is a binding?
Binding is a variable, is used in order to catch or holds a value.

3. What is an environment?
Set/collection of bidings and values at that point in time.

4. What is a function?
Expression wrapped in a value and can be executed by calling that function.

5. Give an example of a function.

> function sumNumbers(num1, num2){
  var result = num1 + num2;
}

6. What is a side effect?
Any effect other than that return value, for example operation that require user interaction.

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

prompt("This is a side effect");
console.log(Math.max(2,4));     // 4

8. What is control flow?
When our program contains more than one statement then they are executed from top to bottom.

9. What is conditional execution?
When the program has to execute different branches based on situation at hand.

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

1 Like

Some good answers, here, @Omar!
I can see you’ve really thought carefully about the different concepts.

Yes, that’s right… and I would just add that the decision about which “branch” to take is based on whether a condition (a Boolean expression) evaluates to true or false  for each particular input.

Keep on learning! You’re doing great! :smiley:

Some really good answers, here, @arod773!

Just a couple of observations to clarify a couple of points:

The keyword ( let , const , or var ) is what declares the binding. The value is actually assigned to the binding name, and it’s this name (and not the keyword) that you use to reference the value whenever you want to use it.

  • Conditional execution is invoked using the keyword if (and else ).

  • Loop is not a keyword (it doesn’t form part of the programming language’s syntax). It just describes a type of statement in JavaScript (an iteration, or a repetitive loop). The keyword while is one of the keywords used to invoke one type of loop. Loops do contain a condition (which decides whether the loop continues, and when it is exited), so we could also consider loops to be a type of conditional execution, but generally we just refer to them as loops or iterations.

  •  true / false are values (Boolean values), and not keywords.

1 Like

Some good answers, here, @Batist_Van_Houtte :ok_hand:

Just one clarification…

console.log() always produces a side effect: it displays an output in the console (in your example, the sum of 3 and 4 i.e. 7).

Math.max(3, 4) would be an example of a function that produces a value i.e. 4

Keep on learning! You’re doing great! :smiley:

Very good answers, @LXSO!

Yes, that’s right… and I would just add that the decision about which “branch” to take is based on whether a condition (a Boolean expression) evaluates to true or false .

Keep on learning! You’re doing great! :smiley:

1 Like

1. What is an expression?

An expression is a piece of code that results in a value.

2. What is a binding?

Binding is the act of assigning a value to a variable.

3. What is an environment?

An environment consists of various bindings and their attributed values in a current state of program development.

4. What is a function?

A function is a part of the program that describes what is to be performed.

5. Give an example of a function.

prompt(“Enter Password”);

6. What is a side effect?

A side effect may speak to the internal machine, preparing it for future statements.

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

console.log()

8. What is control flow?

The program is read from top down, in the likeness of a story.

9. What is conditional execution?

A branching scenario based on a IF, THEN, ELSE type statement.

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

IF invokes a a conditional execution.

1 Like
  1. An expression is something that returns a value.
  2. A binding is a handle to hold onto a value.
  3. An environment is a set of bindings and values.
  4. A function is piece of program wrapped in a value, which can be applied.
  5. We could have a function “doubled” which returns 2*x when we pass it x.
  6. A side effect of a function is when it produces something else than a return value, for example showing a dialog box or writing text to the console.
  7. alert produces a side effect, Number produces a value.
  8. Control flow is how execution moves from one part of the program to the next.
  9. Conditional execution refers to constructs which allow to guide the control flow depending on circumstances (as defined by particular values of the environment).
  10. if, switch, etc
2 Likes

I think I’m getting close to the concept.

Thanks for your help.
I’ll be around asking questions :wink:

1 Like

I was having trouble coming up with for the binding question, I saw it as a place holder, a handle makes more sense.

2 Likes

Since then I’ve read a more fun way to think about bindings, p. 27 of Eloquent Javascript:

You should imagine bindings as tentacles, rather than boxes. They do not contain values; they grasp them—two bindings can refer to the same value. A program can access only the values that it still has a reference to. When you need to remember something, you grow a tentacle to hold on to it or you reattach one of your existing tentacles to it.

2 Likes

hi,

thanks for the tips, i am doing a part of the course again, i am really feeling uncomfortable, bracketss " " upper/low case… here it matters; when i was reading and listening i did understand the logic… but almost nothing works what i try to do so… so bad that i started another course… but i will try every day a bit off the java script course… who knows it will work for me that way?

1 Like

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

  1. Binding is when you point/reference a variable to a value

  2. Environment is the the collection of bindings and their values at that point in time of the programs existence.

  3. A function is a group of code that can be called by the program to compute a value

  4. alert(“”);

  5. If a statement or function modifies the state of something else (outside its own scope), then it is producing a side effect.

  6. let num = 0;
    const func = () => {
    num = 1;
    return true;
    }
    func();

  7. Control flow is simply the order in which we code and have our statements evaluated.

  8. Conditional execution means that some part of the code is going to be executed only if certain condition
    is fulfilled( true ).

  9. Conditional expressions, eg IF …

1 Like

Some good answers, @SDoyle!

That’s a good example of a function that produces a side effect (displaying an output in the console). How about another example of a function that just produces a value, with no side effect? Do you understand the difference?

1 Like

Nice answers, @letscrypto! :ok_hand:

I would also add that the decision about which “branch” to take is based on whether a condition (a Boolean expression) evaluates to true or false . This is key to how conditional execution operates within a program.

Keep on learning! You’re doing great! :smiley:

2 Likes

Hi @pascaldeb,

If you are finding it really difficult then you must take your time. When you are learning a programming language you need to understand certain concepts, get them working, and feel comfortable using them, before you can really move on to the next stage, because so many of the basic concepts are building blocks for more advanced ones.

One of the best pieces of advice I can give you, and Ivan mentions it in his videos, is to just play around with the code yourself. If you’re finding that you think what you’re coding is ok, but then it doesn’t actually execute, you probably need to try executing something simpler first. As you are building up your code, use console.log() a lot to check it still works after you add each extra line, or section. That way it’s easier to spot and fix the error before it gets hidden in a forest of brackets, quotes and tentacles — a reference there to the binding octopus used as an analogy in the course book :wink:

Rewatch the videos, but introduce your own little tests, such as pause it and then try to code the next bit before you watch Ivan doing it. Then check and recheck it for all the details, such as the brackets, quotes, operators etc.

Do a search for YouTube videos on specific JavaScript concepts. There are loads of them out there, and really it can be trial and error finding ones that explain things in a way that suits how you learn. Once you find one you like, don’t just watch it once, but replay it, or watch it really slowly, pausing and replaying certain bits as you code along at the same time.

That’s also wise to have a break sometimes and start something else in between. But don’t leave it for too long, otherwise you’ll forget what you have learnt, and find it much harder to get back into the flow again.

Find what works for you, and enjoy it. If it really becomes a torture then just concentrate on another course, there are loads of different ones in the academy. :slightly_smiling_face:

1 Like

An expression is a fragment of code that produces a value.
A binding is something that catches and holds a value.
An environment is the existence of bindings and values at a given time.
A function is a bit of program wrapped in a value.
An example of a function is a box for user input eg, prompt (“enter name”) with a box to put your name in.
A side effect is something functions can produce. An example of a side effect is showing a box or writing text to screen.
Function math.min produces a value, function.
Control flow is when the program contains more than one statement.
Conditional execution is used when you want to return a specific thing, it is conditional on that.
The keyword you need to invoke this is “if”.

1 Like