Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Break down defer statements in GoLang

Basic ConceptsWhat are the characteristics of the deferred statement defer in Go language? When is it usually used?The deferred statement(defer statement) in Go language has the following characteristics:Deferred Execution: Deferred statements are executed before the function containing them exits, regardless of whether the function returns normally or encounters an exception.Last In, First Out (LIFO): If there are multiple deferred statements, they are executed in the order of last in, first out (LIFO). In other words, the last deferred statement is executed first, and the first deferred stat...

689 0       DEFER GOLANG


  Behavior of defer function in named return function

In Go, there is a special concept of named return value in function where a returned value can have name. For example, below is a named function in Go.func returnNamed() (i int) { i = 1 return}When the function returns, the return value i will have a value of 1. Also, Go has a concept of defer which will execute a function just before the calling function exits. This is similar to what finally block does in other languages such as Java. For example, a defer function can befunc deferFunc() { defer func() { fmt.Println("In defer") }() fmt.Println("Start")}Both return and defer can change th...

3,859 0       GOLANG DEFER NAMED RETURN DIFFERENCE


  Load and execute JavaScript

When we load and execute JavaScript in a webpage, there are many points we need to care about because of its design and feature. There are two features about JavaScript execution in a browser: 1). The JavaScript codes will be executed immediately once loaded;2). When JavaScript codes are being executed, they will block the following contents (including page rendering and other resources downloading). So if there are multiple js files to be loaded, these codes will be executed sequentially.Since JavaScript codes may operate HTML DOM tree, browsers generally will not download js files in paralle...

9,314 0       JAVASCRIPT LOAD ASYNC DEFER EXECUTE