Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

what is synchronous and asynchronous in javascript

Synchronous:
- In synchronous operations tasks are performed one at a time and only when one 
is completed, the following is unblocked. In other words, you need to wait for a
task to finish to move to the next one.

Asynchronous:
- In asynchronous operations, you can move to another task 
before the previous one finishes.
Comment

what is synchronous and asynchronous in javascript

Synchronous: In synchronous operations tasks are performed one at a time and only when one 
is completed, the following is unblocked. In other words, you need to wait for a
task to finish to move to the next one.

function getUsername(callback) {
    setTimeout(() => {
        console.log("Alextz")
        callback()
    }, 2000)
}

getUsername(() => console.log("getUsername callback called"))

Asynchronous:  In asynchronous operations, you can move to another task 
before the previous one finishes.


function getUser(callback) {
    setTimeout(() => {
        console.log("Alextz")
    }, 2000)

    // get executed even though the user has not printed yet
    callback()
}

getUser(() => console.log("getUser callback called"))
Comment

javascript synchronous and asynchronous list

function f1() {
  // some code
}
function f2() {
  // some code
}
function f3() {
  // some code
}

// Invoke the functions one by one
f1();
f2();
f3();
Comment

PREVIOUS NEXT
Code Example
Javascript :: expression expected.ts switch case 
Javascript :: create multidimensional array with foreach javascript 
Javascript :: explicitly import from lodash 
Javascript :: add link in react table to specific column 
Javascript :: repidme 
Javascript :: javascript border textbox 
Javascript :: create a friend component react js 
Javascript :: Alternative Syntax For Backbone Simple Template 
Javascript :: Getting current location from browser Chrome and Firefox console 
Javascript :: array string to length number 
Javascript :: How to Compare Strings Using localeCompare 
Javascript :: Function Returning This 
Javascript :: js set height of element 
Javascript :: Below Means Person is A Constructor Function 
Javascript :: Both This Have The Same Value 
Javascript :: Use regular function with DOM event listeners, when using "this" keyword 
Javascript :: validar fecha jquery 
Javascript :: ticket 
Javascript :: vuejs router Cannot GET /about 
Javascript :: telerik mvc grid add row 
Javascript :: joi custom validation read data for all fields 
Javascript :: regexp look for letter followed by 3 digits 
Javascript :: get aggregate sum value in kendo grid footer jquery 
Javascript :: v-if disable vue 
Javascript :: loading indicator react native 
Javascript :: jquery datatable searchpane pagination not working 
Javascript :: html select structure 
Javascript :: create useTransaction 
Javascript :: js proxy track nested object 
Javascript :: plumsail on change event value 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =