Functions - Reading Assignment


#202
  1. function functioName( parameter){
    block of code;
    }
    Ex. function addition(a,b){
    return a * b;
    }

  2. When we use let for declaring the variable in a block, it creates local binding. Whereas when we use var for declaration then it crates global binding.

  3. Pure functions are those which does not create any side effect and they doesn’t rely on side effect from other code.


#203

How can you create a function in Javascript?
There are a few ways: Simply declaring one with the syntax

Const ahab = function ( arguments )
{
function code
};

This way the binding to ahab is the function result with the given arguments.

What is the difference between var and let in regards to scope?
typically bindings are confined to their local scope, the var binding is more broad.

What is a pure function?
This is a function that is not reliant on the state of any other part of the program. Typically it calls no global bindings that can change, nor does is rely on the effect of any other part of code.
This means that to test a pure function, simply calling it with a set of arguments should always yield the same result.


#204

What are anonymous functions?
And how do you use them?


#205

1 Create a function in JS by using the keyword function, then giving a set of parameters and then a body containing the statements to be executed.
2_let_ creates a local to enclosing block but not the enclosing function.
3 A pure function specific kind of value producing function with no side effects and doesn’t rely on side effects from other code. Same input always same output.


#206

How can you create a function in Javascript?

  • A function is created with an expression that starts with the keyword function.
  • Functions have a set of parameters and a body, which contains the statements that are to be executed when the function is called.
  • The function body of a function created this way must always be wrapped in braces, even when it consists of only a single statement.

What is the difference between var and let in regards to scope?

  • Bindings declared with let are in fact local to the block that they are declared in.
  • Bindings declared with the var keyword, are visible throughout the whole function that they appear in - or throughout the global scope, if they are not in a function.

What is a pure function?

  • A pure function is a specific kind of value-producing function that not only has no side effects but also doesn’t rely on side effects from other code—for example it doesn’t read global bindings whose value might change.

#207
  1. A function is created by using an expression that starts with the keyword function.

  2. Var defines a global or local variable regardless of the block scope, while let declares a variable limited to the block, statement, or expression.

  3. A pure function doesn’t rely on side effects.


#208

1- How can you create a function in Javascript?
A Function is created with an expression that starts with the keyword “function”. A function can have
or not a set of parameters and a body. This body will containt the statmenet of code that will
execute when called. This body is be enclosed with braces even if it contains only one statement.

2- What is the difference between LET and VAR in regards to schope?
“let” bindings will be visible localy inside the block code they are created in. ie. If created inside a loop within a function, they will be not visible before and after the loop. Only visible inside the loop.
“var” binding declared within a function inside a loop will be visible inside and outside the loop. Only within the
function.

3- What is a pure function?
A pure function is function that when it is called it has no side effect and also it releys on no side effects of other
function that are outside this function.


#209

Hello all,

var maxRateInWei;
var slippageRateInWei;
function expectedRate () {
Contract.getExpectedRate(tokenSrc, tokenDest, tokenQty, function (err, res) {

if (!err) {
    maxRateInWei = res[0]; //String(res[0]);

    max = maxRateInWei.c[0] * tokenQty;
    slippageRateInWei = res[1];
    min = slippageRateInWei.c[0] * tokenQty;
} else {
    console.log(err);
};
const maxRate = max/Math.pow(10,Math.floor(4));
$("#maxRate").html(maxRate.toFixed(3));
const minRate = min/Math.pow(10,Math.floor(4));
$("#minRate").html(minRate.toFixed(4));

});
}

How can I access to variable " maxRateInWei " from outside of the function?


#210

I wanna be able to use maxRateInWei as an argument of another function


#211
  1. How can you create a function in Javascript?

Use the FUNCTION tag, put parameters in parentheses, place commands to be executed in the body, and enclose it all in curly brackets.

  1. What is the difference between var and let in regards to scope?

“let” makes it local to the block of code. Apparently “var” is an older command used to make it more general?

  1. What is a pure function?

Essentially, it’s a function that will work within that context and any other context because it does not rely on side effects.


#212
  1. How can you create a function in Javascript?

Wih the word function()and {}.

  1. What is the difference between var and let in regards to scope?

Let is local inside of a loop,the code before and after he loop can no see it!

  1. What is a pure function?

A pure function doesn’t depend on and doesn’t modify the states of variables out of it scopes


#213
  1. How can you create a function in Javascript?
    Name the function and bind it with const
    Write the parameters of the function
    Then add the body which contains the statements that are to be executed.

  2. What is the difference between var and let in regards to scope?
    var is a binding visible in the whole function or global.
    let is a local binding (only visible inside of a loop).

  3. What is a pure function?
    A pure function is a specific kind of value producing function that has no side effects or rely on side effects from other code. It also doesn’t read global bindings which can change.


#214
  1. How can you create a function in Javascript?
    Use the keyword ‘function’
    function doubleMe(x) {
    return x*2;
    }

  2. What is the difference between var and let in regards to scope?
    Let limits the scope to the block, while var is used for more global access (depending on where it is used).

  3. What is a pure function?
    A Purse function runs on it’s own without any dependency to the state. It is a value function that produces no side effects.


#215

Hey, sorry, I am not posting any answers here. I was reading the eloquent Javascript on Functions, when it suddenly stopped being displayed correctly, at first it seemed like all the Javascript / CSS formatting was gone, and then it looked like no format encoding (UTF 8 etc…) was gone and now, on Chrome it only displays question marks and non sense. It still works on Safari though. Weird.


#216

�Y���tA]�249;a��ݳp�;J�cC{�!ô�>�J�ha�#4�@u� 0~����� �O��3ڠ����\���e���p���f�?�z�eJN�'V-jp�����h�f�[����k������(���O�N��BXh��m���ǿ]�Uw���@|�����5E��v�&��r�ˤ>V]z�����@33��w�H ��8!M�J�f�m��Ŷ�-5DI��>�d��4��*e�&�7���l��w@Q�N*3R�r��Ґ��i�b���6��7�QShKI�)�2{E?{u� (�^�G�& ��'���h#��C��3���|^�X��!�BL� ��ߒ~:�mC�v���=�A�W5�x[������-1Z.gr{�V,�����%haFI!�����d0 �C� �H�X��p��<�l���,+��Ѥ��a���u�XN�g% M!x�"�f�ƉG%�8����/'�u�����0�����Ќ�9��r�x�(��Q @�a�H+������0�!z��܂5(D@H˱�e�yQݸh28��p�ȗ(�@t�G�c��â��7ٿ�,��I�����?'�~�2�,�T�zP�:��ǃyV�^�рN��X�� ��g_��{�P�������n8��X�a�zi��F�D F�^FaE@���)�ƹz�/��7�Œ�VVrK�,��� Ҁ=A�@a �8<�^�j߰o�ڒItR�˭�ҫ����w���!����48L2 \6�]� ���<�37��s���Y)9i��Úpu5�M ۚ���6������5p����H9��� �C13����h����/�K ﷀK�^���ä��������d����q���~���=[���9��Ha(@@!��b�kg\�Jdg��9�z’�b�^��C��lkX���@�T� @�6aŢ@)��=Y���W�e ��iM�>7�4m���!���_@��館в��u�Ae̔�q�S,���b����>�mK/7 �V�����\e���ej�Ҁ2�¦�9��p���_3=�8Q�Ĩ�m%��<�H�@�!F@�W�����r�::S�����N�<�$�bP��a�,P ����Y���9;U�ܵg%��#pߤ=(r��0+�]X��ى4��H����s�б�f1������7�ify�������X~��p!� ���3�T& x���T颣��xo��I��>+pF�����|Q͡Eͫ_�3�?b�/Te��/��ŭ����� o�4Th c��4��Y:�WS ^\!>���B>�g�/�TsWO��������0'�f�bP�� Pc�/��7�_M��Ģ���G’���b��ܴ�’���9�a��W��Iy�s Yq"���5�GI�^��x1Sw���iN~��~�y �C�oe���QMc !����9e�0����)$V���o=� ����y�Į�:��ϛ�Tj�Ӈ�u#EQ�!~{�w���9��x��2�E��<�!&�xL7V�L��e�t2����P ��2�a��p������qt)�zn�_B�H밻 ���Q$�(Q�����/B�/���e��z� �̿�_^�������1���p�h��8ŸL�"Xh�jD�À�ǧ����~�㑱�aHt�n�O�ՙ��0a!��]��?i��&% �-E��U����p���6�.�Flą�:V��;�qw��凪x%��5w��a&z&�ݼa@ l�Y���l��ݹ(��%�������;G008���"��_}�_V�p׌�O�ՙ3�H�$��ր���a���(/�u� ������̏!�|�a��'#a]�* ��cp�>���H���P��w���B��\��~���7�i �;��������fp!�����?EEcP�02��lwW%4��q���֩�U�p�.�盁�����QfC@�U�B�����"q��^��a�@A[ia0��co�c1H� D���������c�敩фL�b=)&�4���و��,+��QEš�K�������zT�~}�� ����@���?gm�H%��H|�9gZ�a!����Ei�!��12�k���e���~�sĆE!����7 >�QD��hB��"�)��!���{9y�5�XYJ��ft����Zw֕��\�u� ���n �-����xG[���ny&0�f=�� �l#UZ�@�]���wlDG��^�SB c�MjAe:j�P���+e�P��&��-kT�<��12M���9�H�Ǜ�����3�jI���k��6�ci��y\�L4<C9���H��O������sV[�J@VX(��p!���6(@“�B���+5Ȯ��i�E2}2�w:������ 7�d?�l��W�%����^F�E c��V�VN��� a+_�(�^Gc��[$��e&\g�,�X�o+��n��~��t\� {�����q�\���@f �!�8IU���4s�\�V��etPQ|�8����r� ���K�q@’������� lqה�=�k��L7�i���!?)PP p!���m΁C�����S�ŪX#t|�X�7b��:��X�8Ya���”|1��7�ؾτa�p�92�T ����saJL�jQe r�a�ɲ ��pi�P���e��԰y��hr�@�5�_�1~@ߥQ|����̆��œ�’�h?�� �=Z�@[-�H��a+���h����g�� �'�Uَ��A]_����~_�&��b�!�%�Awe@L�U� hPӮ�=�� ���@����/V�Ҳ�V�e~_���LkwU./ �_c��!��w�M�aPy�!���L��"��)�:N�O��C�Ǫ�>�aB�8.NH!� >� �"��?�Ue���:�Ǖt�AÆ�a>�o���$�J;��5T6�?�84O��ق0������@ P�,@�޾�@���3:��=!�5�n���W����!��bgP��� 0��kg��2����o7��W$�U�px\DWQh��t��rv�y:6�JQO�A.OK�v���wd’[�xξ�A��"�a޼V� ��y#S�1���@�HKZ�x�q�0’� �wD���[�� �e��s�õj�N�{9�Se������.��+SS�O]�@�.LȴMD^5��+|���u%�z��@�I���| ��� � �9�@YCx�����G�Y��۶�a!����a��F��f����n�SZ�O��>���ܗ@��"�z��[8��%��9�4��+�N$w�B��vf��Q]a�9���~3B�0�8W#צ�C��3� ��"�1�@KT��F���s�a(�_=�?�u>����'Y�+�ny�+���[I>������'�+��vu'�<�5:SH �#.� 05� ��h��v�߁����F�"&Tmj��.�Oc�e4�A�{�� �8!���Ga���")�D�+4�sy��D�@nifd�D�V���h��fkL� w��c/[�yB�Op������I�������V�Iݸ��/�$�Ц!]ߊ7�F[��D���a�&�D���[�ID5:��p�P�VX��#PBJ 妀��]����/����;��g��[B��n9q,w���>E�!�#� �rN@��&z �aRh�ض����!н����{X!���R�4�@"��ƭ������A�>]�ZA������َIN��]u�WDzi�\����F��T ���!ܗݕ��o��;� N ����Z-�z�:�f3~�gnd�[S�r����� �� O��������-BY�8JL��ï&4@9� iCM+��&7(L��@�Y�Qg����g?��3�o�?2�^��P�v�/Hr��#�r?lB��?O�� ��(�T�C˶�N��q%[M�\���3�|�����i��߯AM�B�������y<


#217
  1. How can you create a function in Javascript?

A function is created with an expression that starts with the keyword function
. Functions have a set of parameters (in this case, only x) and a body, which
contains the statements that are to be executed when the function is called.

  1. What is the difference between var and let in regards to scope?

Bindings declared with let and const are in fact local to the block that they
are declared in, so if you create one of those inside of a loop, the code before and
after the loop cannot “see” it.

In pre-2015 JavaScript, only functions created
new scopes, so old-style bindings, created with the var keyword, are visible
throughout the whole function that they appear in—or throughout the global
scope, if they are not in a function.

  1. What is a pure function?

A pure function is a specific kind of value-producing function that not only
has no side effects but also doesn’t rely on side effects from other code—for
example, it doesn’t read global bindings whose value might change.


#218
  1. Function starts with the keyword function, have a set of parameters and a body , which must always be wrapped in braces. For example:
    function name(a){
    console.log(a);
    }

  2. Visible only after the announcement and only in the current block. It is impossible to re-declare (in the same block). When a variable is declared in a for (let …) loop, it is visible only in this loop. And each iteration has its own let variable.

  3. The function returns exact the same result each time it is called with the same set of arguments and has no side effects.


#219
  1. How can you create a function in Javascript?
    Use the “function” keyword i.e. function_name (input parameters) { code snippet}

  2. What is the difference between var and let in regards to scope?

Var has global scope while let has scope only within the code block

  1. What is a pure function?

Value producing function that produces no side effects nor relies on another code’s side effects