- A fragment of code that produces a value is called an expression.
- To catch and hold value JavaScript provides a thing called binding or variable. Bindings do not contain values, they grasp them. The words var, const and let are used to create bindings.
- The collection of bindings and their values that exist at a given time is called an environment.
- A function is a piece of program wrapped in a value. A function allows you to define a block of code, give it a name, and then execute it as many times as you want. A function can be defined using a function keyword and can be executed using the () operator.
- console.log();
- Showing a dialog box or writing text to the screen is a side effect.
7.prompt(âEnter passwordâ) produces a side effect.console.log(1+2) produces a value ,3. - When your program contains more than one statement, the statements are executed from top to bottom.
- Conditional execution is when we want to create a branching program, and the program takes the proper branch based on the situation at hand.
- Conditional execution is created with the keyword âifâ.We want a code to be executed if, and only if, a certain condition holds.
1. What is an expression? A fragment of code that produces a value.
2. What is a binding? Javascript produces âbindingsâ or âvariablesâ as a way to catch and hold values.
3. What is an environment? The collection of bindings and their values which exist at a certain time.
4. What is a function? A piece of program wrapped in a value.
5. Give an example of a function. prompt(âEnter passcodeâ);
6. What is a side effect? When a statement changes the state of the machine and affects statements that come after it.
7. Give an example of a function that produces a side effect and another function that produces a value. Side effect: opening a dialogue box: prompt(âEnter passcodeâ);. Value: Math.max
8. What is control flow? If a program has more than one statement then a control flow is the way the statements are executed like a story, one after another.
9. What is conditional execution? A program with a branch in it. The program takes the proper branch depending on the situation at hand.
10. What kind of keyword do you need to use to invoke conditional execution? If
- What is an expression?
- What is a binding?
- What is an environment?
- What is a function?
- Give an example of a function.
- What is a side effect?
- Give an example of a function that produces a side effect and another function that produces a value.
- What is control flow?
- What is conditional execution?
- What kind of keyword do you need to use to invoke conditional execution?
-
An expression is any valid set of literals, variables, operators, and expressions that evaluates to a single value.
-
A binding or variable is a way for the program to remember a value. One usually use let, var or const in JavaScript.
-
The environment is the collection of bindings and their values at any given moment.
-
A JavaScript function is a block of code designed to perform a particular task. The syntax is basically:
function myFunction(a, b, c) {
return a * b / c
}
(Or any other computation with the three variables.)
-
See no. 4.
-
A side effect is any change that is observable outside the a called function other than the pure computation and its return value.
-
alert(âAlert is a function thatâs producing a side effectâ);
console.log(4 + 6); produces a value and displays it in the console (that should probably count as a side effect aswell)
-
The control flow is the order in which the computer executes statements in a script. Itâs achieved mostly by conditionals (if, else and else if statements) and loops. Itâs about determining âwhereâ the program should go, depending on the circumstances.
-
See no. 8.
-
See no. 8. (Iâve seen the switch statement, but I donât know how it works.)
- Coding that produces a value.
- Code function that binds key words/values to an predetermined output.
- Collection of existing bindings at the current point of time.
- A piece of program wrapped in a value.
- prompt(âEnter passcodeâ);
- Showing a dialog box or writing text to the screen.
- console.log(Math.max(2, 4));
// â 4 - Programs that follow a reading logic, eg readin code from top to bottom
- Program to execute code only when specific conditions are met.
- If
-
Anything that is added to a value is an expression. Every value that is written literally is also an expression.
-
Bindings, or variables, catch and hold values.
-
The collection of bindings and values that exist at a given time.
-
A value that contains a piece of program.
-
console.log
-
Showing a dialog box or writing text to the screen.
-
Side effect:
console.log(Math.max(2, 4));
// â 4
Value
console.log(Math.max(2, 4) + 100);
// â 104 -
It is the way in which the program determines the order of execution of its statements - from top to bottom.
-
The program will execute a command if one or more conditions are met.
-
IF, which can branch, e. g. ELSE
1. What is an expression?
A fragment of code that produces a value. Every value that is written is an expression. An expression can be thought of as a sentence fragment, where multiple expressions create a statement, which is comparable to a full sentence.
2. What is a binding?
A word / character(s) that hold(s) a value and can then be used as an expression. A variable - refers to attaching a value to a variable / binding.
3. What is an environment?
A 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, which can be applied in order to run the wrapped program. A block of code designed to perform a particular task.
5. Give an example of a function.
console.log(âcatâ);
alert(4*100);
for(let number = 0; number <= 12; number = number +2) {console.log(number)};
6. 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 - such as showing the return value in 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: alert(âhello good sirâ)
value: console.log(Math.max((424%25), 25));
8. What is control flow?
Refers to when a program contains more than one statement, the statements are executed from top to bottom (left to right). It is the order in which the computer executes statements.
9. What is conditional execution?
An âIfâ program where depending on the outcome of a certain condition, a different program is executed, such as âif x happens, do a, else do bâ.
10. What kind of keyword do you need to use to invoke conditional execution?
With the âifâ keyword. âWhileâ works as well however this is for creating a loop âwhile x is true, do a, otherwise stopâ
- An expression is any valid unit of code that resolves to a value.
There are two types:
- With side effects - (those that assign value to a variable) for example, The expression x = 7 This expression uses the = operator to assign the value seven to the variable x. The expression itself evaluates to seven.
- Those that evaluate and resolve to a value. For example, coding 3+4. This expression uses the + operator to add three and four together without assigning the result, seven, to a variable.
-
A binding is how a program remembers things and keeps an internal state. JS provides binding or variables to catch and hold values.
-
an environment is the collection of bindings and their values that exist at a given time.
-
A function is a 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.
-
An example of a function is in a browser environment, the binding prompt holds a function that shows a little dialog box asking for user input. User can input things like A user name or passcode.
-
A side effect is a programing statement displaying something on the screen or showing a dialog boxâthat 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.
-
An example of a function that produce a side effect is prompt(âEnter passcodeâ); and another function that produces a value is console.log(Math.max(2, 4));
-
Control flow is when a program has multiple statements and executes them one by one from top to bottom.
-
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.
-
To invoke conditional execution we use the âifâ, âelseâ or âelse ifâ keywords.
-
An expression is a fragment of code that produces a value.
-
bindings can be imagined as tentacles rather than boxes. They do not contain values, they grasp them. Javascript provides a thing called binding to catch and hold values.
-
An environment is a collection of bindings and their values that exist at a given time.
-
A function is a piece of program wrapped in a value.
-
In a browser environment, the binding prompt holds a function that shows a little dialogue box asking foe user input. an example would be a little box on a web page that asks a user to input a password.
6.A side effect would be, showing a little dialogue box or writing text to the screen.
-
A function that produces a side effect would be a little dialogue box on a web page that asks a user to input a password.
A function that produces a value is said to give back a value. an example would be inputing a value to receive a value kind of like asking a question to get the answer. -
when program contains more than one statement, the statements are executed as if they are a story from top to bottom.
-
A conditional execution is what I would call a pathway of results based on user choices made in a program. It is described in the reading as follows;
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. -
a conditional execution is created with the keyword if
-
An expression is a fragment of code that produces a value
-
Binding is is used to capture and hold functions. Let ⌠Indicates the sentence is going to define binding and if we add = we can then add an operator and Expression.
-
A collection of bindings and their values that exist at a given time is called The Environment. Like when you start a Web browser up and Mouse and Keyboard are active.
-
By putting an parentheses after the expression that produces a function value. a value between the parentheses are given to the program inside the function.
-
A pass code prompt at start of a Web browser page.
-
Return values - Showing a dialog box or writing to a screen is known as a side effect. If something is modified outside its on range it is a side effect that has been produced.
-
@thecil hi mate, please help. I am struggling with this. Ive read the book but its still not sinking in unfortunately. i could copy an answer down but what is the point in that.
I will try answer the rest any wayâŚ
I have so far a âSide Effect is something you type on the screenâ. Would it be prompt = (ârobertâ);
a Function that returns a value console.log(2+6); and would return 8?
So what exactly would a side effect be used for? im just trying to get an example in a real world scenario of when it would be used. then i would understand better.
Thanks guys.
-
A control flow is when youre program contains one or more statements. Like in the book it describes working out the Square root of a number. It reads it like a story, from top to bottom.
-
Conditional Execution is where youre not programming Linear commands, you may want to branch of to another statement and come back in the end to a final result. You can use braces to group these statements together to get a end result.
-
if
Greetings Sir, Hope youâre having a great day.
Well, âSide Effectsâ per se means anything that happens other than a return of value.
A Real-World example would be â
Suppose thereâs a function to check a studentâs answer to a question on a webpage. Lets call this Evaluate()
. Now Evaluate()
evaluates the answer and returns true(correct answer) or false(wrong answer). This is called âValueâ returning function.
Suppose If Evaluate()
also brings up animation in the webpage to celebrate the studentâs right answer, this would be a âSide Effectâ. Furthermore, if Evaluate()
tries to change a global variable called "isStudentPassed"
from false to true, then this would also be considered as a âSide Effectâ.
Any change made to variables or state outside of the function will be considered as a âSide Effectâ.
If you want to dive deeper, check this article out and jump to the âSide Effectsâ topic. Javascript Interview questions - Side Effects
Hope this clears it. If any doubt please feel to reach out again. Thanks.
Happy Learning
-
What is an expression?
An expression is a fragment of a statement -
What is a binding?
A binding is a variable that allows you to grasp hold of values so that they can be used in expressions. Bindings are not fixed to one value and can be updated by simply using the = operator -
What is an environment?
A collection of bindings and their values -
What is a function?
A function is a specific section of code that is called to perform a specific task -
Give an example of a function.
alert (âHello Worldâ) -
What is a side effect?
If a statement or function modifies the state of something else which is outside its own scope, then it is producing a side effect. -
Give an example of a function that produces a side effect and another function that produces a value.
side effect --> prompt(âEnter your passwordâ)
value â> console.log(Math.max(5,10)); -
What is control flow?
Control flow is the order in which the computer executes the statements of the program - from top to bottom -
What is conditional execution?
A branching route which is only taken if certain conditions are met. -
What kind of keyword do you need to use to invoke conditional execution?
if or else or else if
- What is an expression?
Itâs a piece of a code that produces value, which contains variables, operators and literals. - What is a binding?
Itâs reference a variable to a value - What is an environment?
Itâs a collection of bindings and their values in that moment in the program - What is a function?
Itâs a section of the program that performs a specific task - Give an example of a function.
alert("Hello " + firstName + " " + lastName) - What is a side effect?
It is when a program or function modifies something outside its scope or design - Give an example of a function that produces a side effect and another function that produces a value.
promt(âenter passcodeâ); - What is control flow?
Itâs the order which the computer executes statements in a script. From top to bottom sequentially. - What is conditional execution?
Itâs when the program has a branching road. When the order of the execution is branches in multiple paths - What kind of keyword do you need to use to invoke conditional execution?
if, else if, else
@Malik you are amazing. you have totally cleared that up for me now.
That is a belter of an article.
Thanks brother.
Rob.
- What is an expression?
Is a code that produces a value, also every value that is is written is an expression. There are smaller expressions inside larger ones, - What is a binding?
Key words define bindings. You can bind a key word by assigning â=â operator. Bindings also catch and hold values, - What is an environment?
Is a set of bindings containing their respective values in memory. This environment is on standby and waiting to run the program when a computer is turned on. - What is a function?
Is part of a program that encompasses a value. When that value is âappliedâ, the program runs, which performs a task or calculates a value. - Give an example of a function.
function greet(); {
console.log(âHello worldâ); - What is a side effect?
A side is the action output of the function; like print on the console or display a prompt. - Give an example of a function that produces a side effect and another function that produces a value.
- What is control flow?
When there is more than one statement, the control flow is the statement on top will be executed first. - What is conditional execution?
When you have statements has a branch that was created with the âifâ or âelseâ keywords, that creates different outcomes. - What kind of keyword do you need to use to invoke conditional execution?
If, else, else if.
- What is an expression?
An expression is a piece of code that produces a value. - What is a binding?
A binding holds and remembers values for later use. - What is an environment?
An environment is a collection of bindings and their values at a given time. - What is a function?
A function is a piece of program wrapped in a value. - Give an example of a function.
let name = prompt (âtype a name hereâ); - What is a side effect?
Showing a dialog box or writing a text is a side effect. - Give an example of a function that produces a side effect and another function that produces a value.
Function add (let a, let b) {return a+b} - What is control flow?
Control flow is the order in which the statements are executed. - What is conditional execution?
Conditional execution controls whether or not the core will execute an instruction. - What kind of keyword do you need to use to invoke conditional execution?
if, else, else if
- What is an expression?
It is a fragment of a code that produces values - What is a binding?
Assigning values to be remembered for later use. - What is an environment?
A collection of binding and their values at a given time. - What is a function?
A piece of program wrapped in a values. - Give an example of a function.
console.log(x + y + z); Each letter can be predefined or not. - What is a side effect?
Showing a dialogue 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.
prompt(âEnter passcodeâ); produces side effects. console.log(x + y + z); produces value - What is control flow?
Execution of a program from top to bottom in form of a story. - What is conditional execution?
Situation based execution of programs. Or non-linear execution. - What kind of keyword do you need to use to invoke conditional execution?
if
- What is an expression?
A fragment of code that produces a value.
- What is a binding?
A binding or variable is an expression that catches and holds a value.
- What is an environment?
The collection of bindings and their values at a given time.
- What is a function?
A function is a piece of program wrapped in a value.
- Give an example of a function.
console.log
- What is a side effect?
changes to the internal state of the machine that will affect subsequent statements.
-
Give an example of a function that produces a side effect and another function that produces a value.
-
prompt
-
math.max
-
What is control flow?
The order in which statements are executed.
- What is conditional execution?
A statement which is executed only if its conditions are met.
- What kind of keyword do you need to use to invoke conditional execution?
if
1-What is an expression?
itâs a piece of program wrapped in a value.
2-What is a binding?
itâs a method used to call a function by putting () after an expression that produces a function value .
3-What is an environment?
itâs a platform that runs java script .
4-What is a function?
Functions are the main âbuilding blocksâ of the program. They allow the code to be called many times without repetition.
5-Give an example of a function.
function show message () {
alert ( â hello! â ) ;
}
6-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.
7-Give an example of a function that produces a side effect and another function that produces a value.
A) a function that produces a side effect:
Math.random()
produces a new random number between 0 and 1 every time you run it.
Math.random(); // => 0.4011148700956255
Math.random(); // => 0.8533405303023756
Math.random(); // => 0.3550692005082965
B)function that produces value :
Math.max()
takes numbers as arguments and returns the largest number:
Math.max(2, 8, 5); // 8
8-What is control flow?
is a way to run a piece of code multiple
times.
9-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.
10-What kind of keyword do you need to use to invoke conditional execution?
if and else .
-
What is an expression?
An Expression is a fragment of code that produces a value -
What is a binding?
A binding is something provided by JavaScript that catches and holds values. -
What is an environment?
An environment is a collection of bindings and their values that exists at any given point in time. -
What is a function?
A function is a piece of program wrapped in a value. -
Give an example of a function.
alert is an example of a function -
What is a side effect?
Is an unintended but useful effect produced by a function. -
Give an example of a function that produces a side effect and another function that produces a value.
Side Effect: In a browser environment, the binding prompt holds a function that shows a small dialog box for user input.
Value: Math.max is a function that produces a value -
What is control flow?
Control flow is the sequence in which a program is executed. -
What is conditional execution?
Conditional Execution is where a program will be directed to perform different actions based on different decisions -
What kind of keyword do you need to use to invoke conditional execution?
if, else, else if are the kinds of keywords used to invoke conditional execution.
-
An expression is a fragment of code that produces a value. Every value
that is written literally is an expression, as are expressions between parentheses. -
A binding, or variable, is used in JavaScript to catch and hold values so that they are not forgotten, and can be used to execute subsequent commands. E.g. let ten = 10;
console.log(ten * ten);
// â 100 -
An environment is the collection of bindings and their values that exist at a given time. This means that when a program starts up, it is already pre-populated with bindings and their values.
-
A function is a piece of program wrapped in a value. Such values can be applied
in order to run the wrapped program. -
prompt(âEnter passcodeâ);
-
A side effect is when the outcome of a particular function or expression changes the internal or external state of the machine running the code, such as when a program shows a dialog box or prints text on a screen.
-
prompt(âEnter passcodeâ); is an example of a function that produces a side effect, whereas console.log(Math.max(2, 4));
// â 4
âŚis an example of a function that produces a value. -
Control flow means that when a program contains more than one statement, the statements are executed as if they are a story, from top to bottom.
-
Conditional execution is when the program is given multiple options and executes one of those options based on the situation (inputs) at hand. E.g.
let num = Number(prompt(âPick a numberâ));
if (num < 10) {
console.log(âSmallâ);
} else if (num < 100) {
console.log(âMediumâ);
} else {
console.log(âLargeâ);
}
- The keyword you need to use to invoke conditional execution is âifâ.