LoginSignup
3

More than 5 years have passed since last update.

JavaScript入門を勉強しなおした

Posted at

リファレンス

Mozilla Developer Network | JavaScript

データ型の種類

  • 文字列
  • 数値
  • 真偽値 true / false
  • オブジェクト
    • 配列
    • 関数
    • 組込みオブジェクト
  • undifined
  • null

真偽値

  • 文字列: 空文字列以外 true
  • 数値: 0 か NaN 以外ならtrue
  • true / false
  • object: null 以外だったらtrue
  • undefined, null -> false

ユーザに対する情報提供

  • alert
    • ok
  • confirm
    • ok -> true
    • cancel -> false
  • prompt(message, placeholder)
    • 入力値
    • null

setInterval setTimeout

var i = 0;

setInterval(fuction(){
    console.log(i++);
}, 1000); //ミリ秒

show = function() {
  console.log(i++)
   var timer_id = setTimeout(function() {
    show();
  }, 1000);

  if (i > 3){
    clearTimeout(timer_id);
  }
}

show();

setInterval 簡単 前の処理の終了を気にしない

setTimeout x秒後に1回

文字列オブジェクト 文字列リテラル

var str = "Hello!"; //文字列リテラル
var str2 = new String("World!"); //文字列オブジェクト

文字列リテラルに対してメソッドが使えるのは,実行系が文字列リテラルを部分的に文字列オブジェクトとして解釈し実行してくれるから

Mathオブジェクト

Math.ceil(5.3) // 6
Math.floor(5.3) // 5
Math.round(5.3) // 5
Math.random() // random(0~1)

DOM

console.dir(window);

window.location.href = "http://example.com";

window.document === document // 同じ

elemnet の style 変更

e.style.color = "red"; // 直接
e.className = "myStyle" // スタイル指定

オブジェクトの追加

var greet = document.createElement("p");
var text = document.createTextNode("Hello, World!");
document.body.appendChild(greet).appendChild(text);

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
3