Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

what is asynchronous

// some functions
function foo() {
	console.log("foo")
}
function bar() {
	console.log("bar")
}

/*  due to the javascript event-loop behavior this code
	is going to be asynchronous but what does that mean?
    
    well, first you need to understand the concept of asynchronous, 
    In computer programming, asynchronous operation means that a 
    process operates independently of other processes. 
*/
setTimeout(foo, 2000)
console.log("faz")
bar()

// this code above is going to print out:
// "faz"
// "bar"
// "foo"

/* this happens because the event loop first executes all the synchronous code 
then waits for the timer to complete and then when it's done puts the callback 
that we passed it in as a first param in something called the task queue where 
it will be added to the call stack and executed
Comment

what is asynchronous in javascript

// some functions
function foo() {
	console.log("foo")
}
function bar() {
	console.log("bar")
}

/*  due to the javascript event-loop behavior this code
	is going to be asynchronous but what does that mean?
    
    well, first you need to understand the concept of asynchronous, 
    In computer programming, asynchronous operation means that a 
    process operates independently of other processes. 
*/
setTimeout(foo, 2000)
console.log("faz")
bar()

// this code above is going to print out:
// "faz"
// "bar"
// "foo"

/* this happens because the event loop first executes all the synchronous code 
then waits for the timer to complete and then when it's done puts the callback 
that we passed it in as a first param in something called the task queue where 
it will be added to the call stack and executed
Comment

PREVIOUS NEXT
Code Example
Javascript :: how make calender in bootstrap 
Javascript :: if statement javascript 
Javascript :: how to remove first element from array in javascript 
Javascript :: get data from google sheets javascript 
Javascript :: use moment js in ejs file 
Javascript :: js remove escape characters from json 
Javascript :: variables javascript 
Javascript :: express send pdf to view 
Javascript :: how to concatenate in javscript 
Javascript :: create callback function javascript 
Javascript :: js array.some 
Javascript :: Javascript number Count up 
Javascript :: how to get variable from url in javascript 
Javascript :: emitting event on socket.io using async await 
Javascript :: selected text 
Javascript :: mean stack tutorial 
Javascript :: jquery autocomplete bootstrap modal 
Javascript :: upload file to database with axios and formData 
Javascript :: array flatten 
Javascript :: js display image from external url 
Javascript :: remove duplicates javascript 
Javascript :: file download jquery 
Javascript :: javascript ajax get 
Javascript :: peerjs 
Javascript :: object.entries in javascript 
Javascript :: get width of screen 
Javascript :: jquery slide 
Javascript :: sum array without loop javascript 
Javascript :: find how many similar object item in an array in javascript 
Javascript :: mongoose rename collection 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =