|
1 | 1 | script tag must be loaded in last, as it won't recognize the body tag, if defined earlier than it.
|
2 | 2 | *************************************************************************
|
| 3 | +==> WHAT IS JAVASCRIPT??? |
| 4 | +- It is a single-threaded language. (can do one task at a time) |
3 | 5 |
|
| 6 | +- It is a non-blocking language (doesnot make other operations wait, if one operation is taking time for execution such as in setTimeout). |
| 7 | + |
| 8 | +- It is a asynchronous concurrent language (can see non- blocking behaviour of JS). |
| 9 | + |
| 10 | +- JS runtime can do only one operation at a time. (Browser, APIs are not a part of runtime hence we are able to perform multiple operations with the assistance of APIs and browser support) |
| 11 | + |
| 12 | +- It has a call stack, event loop, and a callback queue+ other APIs. |
| 13 | + |
| 14 | +- V8 is JS runtime which has call stack and a heap. |
| 15 | + |
| 16 | +- The heap is used for memory allocation and stack holds the execution context. |
| 17 | + |
| 18 | +- DOM, setTimeout XML Http Request doesnot exist in V8 source code. |
| 19 | + |
| 20 | +- Task Queue --> As JS can execute one task at a time, the rest tasks are queued waiting to be executed. |
| 21 | + |
| 22 | +- Call Stack --> the order in which operations are executed. All the operations to be executed are stored in a stack, and follows the stack behaviour for e.g. |
| 23 | + |
| 24 | +greeting=()=>{ |
| 25 | + hello=()=>{ |
| 26 | + |
| 27 | + } |
| 28 | +} |
| 29 | +stack order--> greeting(), hello(); |
| 30 | +hello() will be executed first and leaves the stack, then greeting() will starts to execute. |
| 31 | + |
| 32 | +- Event Loop --> |
| 33 | +JS has a runtime model based on event loops, which is responsible for the execution of code, collecting and processing events, and executing sub-tasks. |
| 34 | +pushes the operations from task queue to the call stack. |
| 35 | + |
| 36 | +setTimeout (fun, 0) --> when set timeout is run with 0 parameter, it means that the task should be delayed until other tasks are completed. |
| 37 | + |
| 38 | +************************************************************************* |
4 | 39 | Javascript is a dynamically types language. We do not have to tell the datatype of a variable.
|
5 | 40 | for e.g. if we are working in python while initializing the variable we have to define its datatype. Whereas, in JS there is no such thing.
|
6 | 41 |
|
|
0 commit comments