1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JavaScriptの基礎(2)

Last updated at Posted at 2025-03-12

※この記事は初学者の毎日のアウトプット用に作成している記事です

<script>タグの追加

HTMLドキュメントとJavaScriptプログラムを関連づける必要がある
その際に<script>タグが使用される

1,<script><script>にJavaScriptプログラムを直接記載
2,<script>タグに外部のJavaScriptファイルを指定してHTMLに読み込む

<script>タグはHTMLドキュメントのどこに記載してもいいが、一般的には<head><head>の中、もしくは<body>タグのすぐ上に記載

console.log()

console.log()は()内の値をコンソールに出力するメソッド
プログラムの開発中の動作確認でよく用いられる

ブール値

コンソールに表示されるtrueやfalseはブール値(真偽値)という
下記のconfirmメソッドはOKとキャンセル二つのボタンが表示され、OKをクリックするとtrue、キャンセルをクリックするとfalseを返す

const result = confirm("本当に削除しますか?");

console.log(result) //コンソールにresultの値を出力

条件文

なんらかの条件がtrueの場合とfalseの場合で処理を振り分ける構文を条件文という

const result = confirm("本当に削除しますか?");

if (result) {
    console.log("削除されました"); // OK を押した場合
} else {
    console.log("キャンセルされました"); // キャンセルを押した場合
}

参考書籍:

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?