Skip to content

Instantly share code, notes, and snippets.

@qkreltms
Last active January 23, 2019 09:38
Show Gist options
  • Select an option

  • Save qkreltms/8db75d470946aa7f29522daf919fa3bc to your computer and use it in GitHub Desktop.

Select an option

Save qkreltms/8db75d470946aa7f29522daf919fa3bc to your computer and use it in GitHub Desktop.
return 시 괄호를 쓰는 이유

여러 줄을 리턴할 때 사용.

출처

리엑트에서 제공하는 예제를 보면 괄호를 사용한 반환을 한다.

render: function() {
	return (
		<div className="foo">
			<h1>Headline</h1>
			<MyComponent data={this.state.data} />
		</div>
	);
}

괄호가 없다면 에러!


일반적으로 사용하는 예제 https://codepen.io/qkreltms/pen/JxoZYP

var foo = function() {
  var x = 3;
  return (
    x 
    + 
    1
  );
};
console.log(foo());

밑의 코드는 에러를 반환함!

var foo = function() {
  var x = 3;
  return 
    x 
    + 
    1
  ;
};
console.log(foo());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment