Tuesday, February 26, 2019

NODEJS FUNCTION AND DATA TYPES

Node.js Function


  1. SettimeOut(): The function  execute only one time in the defined time.
  2. SetInterval() :If not stop execute in the function, works forever in the defined interval time. The function stop execute keyboards in the Ctrl+c keys. Here is example of that.




The output in the code of that.


          3.CallBack Function (): We'll use this function somewhere. Example, The function which function when to execute about lets us decide.

The Node.js has not  such execute compile from top the bottom in the code. Whoever execute out before the execute.Here is exemple of that.




The output in the code of that.



The array printing using foreach is as following. I create name is "dizi" new a array. The array printing value. The array assigned to the k variable. 


The output in the code of that.


Try- catch :

JavaScript's try-catch-finally statement works very similarly to the try-catch-finally encountered in C++ and Java. First the try block is execute until and unless in it is throws an exeption.If the code doesn't throw an exception, then the whole try block is execute.If the code threw an exception inside the try block then the cath block is executed
Last of all,The finaly block is always execute subsequent to the other block.



The finaly block will just about always execute.


Catch block and finaly block runs through code in error even if.


Use Strict 

Strict mode is a new feature in EsmaScript 5 that allows you to plane a program,or a function. This strict function prevents certain error from being taken and throws more exception.

  • Strict mode eliminates some JavaScript silent errors by changing them to throw errors.
  • Strict mode fixes mistakes that make it difficult for JavaScript engines to perform optimizations: strict mode code can sometimes be made to run faster than identical code that’s not strict mode.
  • Strict mode prohibits some syntax likely to be defined in future versions of ECMAScript.
  • It disables features that are confusing or poorly thought out.
  • Strict mode makes it easier to write “secure” JavaScript.

Error because use did not specify the data type of the data variable.


It prevents, or throws errors, when relatively “unsafe” actions are taken (such as gaining 

   access to the global object).


Difference between var and let :

In fact there is not much difference between them same output as seen.



We can also access the "i" variable from the for loop outside the for loop. Writes us the last.
Typed "i" variable outside the loop, but the last value in the for loop.Cause a lot of errors due to scope in complex project.Therefore it causes poor performance.


but if we used LET instead of VAR, that would have happened . as you can see, we can't get out.
(The fact that we want in projects should be in this way. We should only be able to access the "i" variable from within the for loop.



2 - Another difference is "i" defined variable consecutive when we do the first definition of the variable in javascript while processing the last definitions. this may also result in poor performance. If we forget that we have defined x above and re-defined the following, it may cause a decrease in performance.


 But  use to  let variable caused error.




No comments: