0
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?

More than 3 years have passed since last update.

JavaScript勉強メモ4章

Last updated at Posted at 2021-04-19

JavaScript勉強メモ4章

まずはじめに

4. JavaScriptの基本事項

  • 単語の間で空白・改行は自由
    セミコロン(;)は文末に入れると良い

  • 予約語(もともと意味や機能が定義されている単語)は変数名・関数名に使用不可

  • データの種類
    プリミティブ型:

     /*単一データ*/
    apple /*文字列*/
    3     /*数値*/
    

    オブジェクト型:

    /*複数のプリミティブ型またはオブジェクト型を持つデータ*/
    [apple, orange]           /*配列*/
    {width: 100, height: 80}  /*オブジェクト*/
    
  • シンボル
    ユニークなプリミティブ型のデータらしい、オブジェクトのキーなどに使えそう?(勉強中)

  • ラッパーオブジェクト
    いまいちわからない、プリミティブ型もオブジェクト用のメソッドが自動で使える仕組みはあるらしい。

  • strictモード
    望ましくない記述をエラーにできる機能。ファイル全体に有効にするとき、ファイルの先頭に次を記述する。

    'use strict';
    

    特定の関数にのみ適用するとき、以下のように記述する。

    function myFunc(){
      'use strict';
      ・・・
      ・・・
      }
    
  • 型変換のルール

    • 文字変換
    num = 2
    console.log(typeof num)
    >>>number
    
    console.log(typeof String(num))
    console.log(typeof num.toString())
    >>>string
    
    • 数値への変換
    str = "2"
    console.log(str)
    >>>string
    
    console.log(Number(str))
    >>>number
    
    • 理論値(true, false)への変換
    if(0){
      console.log("0という値は真だよ");/*if文が真(true)ならこっち*/
    }else{
      console.log("0という値は偽だよ");/*偽(false)ならこっち*/
    }
    >>>"0という値は偽だよ"/*0は偽(false)だった*/
    

    if文を使わなくてもboolean()を使えば真偽が確かめられます。

    console.log(Boolean(0));
    >>>false
    console.log(Boolean("false"));/* 文字列は""(空白)以外true*/ 
    >>>true
    console.log(Boolean(false));/*値としてのfalseはfalse*/
    >>>false
    
0
0
0

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
0
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?