관리 메뉴

Silver Library (Archived)

JavaScript Expression? 본문

Personal DB/Mainly for Front-end

JavaScript Expression?

Ayin Kim 2020. 11. 24. 11:41
반응형

What is a JavaScript Expression? - Mastering JS

 

What is a JavaScript Expression?

Many frameworks, like Vue, allow you to embed JavaScript expressions in HTML. But what is an expression? Can you put `if` statements in an expression?

masteringjs.io

Expression do evaluate to a value.

0 // 0

1 + 1 // 2

'Hello' + ' ' + 'World' // 'Hello World'

{ answer: 42 } // { answer: 42 }

Object.assign({}, { answer: 42 }) // { answer: 42 }

answer !== 42 ? 42 : answer // 42

answer = 42 // 42

 

Statement do not evaluate to a value.

// `if` statement

if (answer !== 42) { answer = 42 }

//`for` is a statement

for (;;){ console.log('Hello, World'); }

//Declaring a variable is a statement

let answer = 42