Difference between = and := in Golang

Jiwan Jeon·2022년 2월 20일
0

Golang

목록 보기
3/4

✅ What is difference between = and :=

:= is for both declaration, assignment, and also for redeclaration.

ex) foo := 32 is a shor-hand form of

  • 	```
    	var foo int 
    	foo = 32
    	```
  • var foo int = 32

  • var foo = 32

✅ Rules!

  • cannot ues := out of functions
  • cannot use them twice in the same scope
  • can use them for multi-variable declarations and assignments foo, bar := 42, 314
  • can use the shor decalaration to declared with the same name before var foo int = 34
profile
Jiwan Jeon

0개의 댓글