728x90
Display
JavaScript에서의 display 방법:
- writing into an html element, using innerHTML
- writing into the html output using document.write()
- writing into an alert box using window.alert()
- writing into the browser concole, using console.log()
using innerHTML
document.getElementById("demo").innerHTML = 5 + 6;
To access an HTML element, JavaScript can use the document.getElementById(id) method.
The id attribute defines the HTML element. The innerHTML property defines the HTML content.
using document.write()
document.write(5 + 6);
For testing purposes, it's convenient.
But using document.write() after an HTML document is loaded, it will delete all existing HTML
using window.alert()
You can use an alert box to display data
window.alert(5 + 6);
alert(5 + 6);
window keyword는 안써도 괜찮음.
using console.log()
For debugging purpose, you can call the console.log() method in the browser to display data.
console.log(5 + 6);
F12해서 console들어간후 run하면 값이 나온다.
*JavaScript에서 print는 진짜 프린트해줌. (인쇄)
JavaScript Statement(구문)
statement(구문): 코드?
문법!
- Semicolons
- Semicolons sepreate JavaScripte Statements.
- multiple statements on one line are allowed.
- White Space
- JavaScript ignores multiple spaces.
- Line Length and Line Breaks
- for best readability, programmers often like to avoid code lines longer than 80 characters.
- Code blocks
- purpose of code blocks is to define statements to be executed together. (ex. functions)
Keywords
몇개만 예시로 가져옴.
break
continue
debugger
do ... while
for
function
if ... else
return
switch
try ... catch
var
728x90
반응형
'Software Study > Javascript' 카테고리의 다른 글
[2021.01.27] JavaScript 공부 (0) | 2021.01.27 |
---|