[JS] 03. Type

2017. 8. 28. 13:34·JS/JavaScript
728x90
반응형

03_Type.html

<script>
//Types in JavaScript fail into two categories; primitivesand objects.
//Primitive types include: String, Number, Boolean, null, undefined

/////// String ///////
// Strings can be created with double or single quotes.
var a = "I am a string";
var b = 'So am I!';

//Sometimes a string may contain quotation marks.
var statement1 = 'He said "JavaScript is a awesome!"';
var statement2 = "He said \"JavaScript is a awesome!"";
////////////////////////

/////// Number ///////
//Numbers are any whole or floating point integer.
var num1 = 100;
var num2 = 100.10;
var num3 = 0.10;
//////////////////////

/////// Boolean ///////
//Boolean values.
var okay = true;
var fail = false;
///////////////////////

/////// null and undefined ///////
//Define a null value. Null types are values  that represent the absence of a value
var foo = null;

//Undefined types represent a state in which no value has been assigned at all.
//This type is created in two ways: by using the undefined keyword or by not defining a value at all.
var bar1 = undefined;
var bar2;
//////////////////////////////////

/////// Objects ///////
//Creating an object with the constructor:
var person1 = new Object;
person1.firstName = "John";
person1.lastName = "Doe";
console.log(person1.firstName + " " + person1.lastName);

//Creating an object with the object literal syntax:
ver person2 = {
        firstName = "Jane";
        lastName = "Doe";
};
console.log(person2.firstName + "" + person2.lastName);

//obejcts can also have objects as a property.
var people = {};
people.person1 = person1;
people["person2"] = person2;
console.log(people["person1"].firstName);
console.log(people.person2.firstName);

//Properties that have not been created are undefined.
var person = {name: "John Doe"};
console.log(person.email); //undefined
/////////////////////////////////

/////// Array ///////
//Creating an array with the constructor:
var foo = new Array;

//Creating an array with the array literal syntax:
var bar = [];

//The array literal returns a foo.length value of 1:
var foo = [100];
console.log(foo[0]); //100
console.log(foo.length); //1

//The array constructor returns a bar.length value of 100:
var bar = new Array(100);
console.log(bar[0]); //undefined
console.log(bar.length); //100

//Using the push(), pop(), unshift() and shitf() methods on an array.
var foo = [];
foo.push("a");
foo.push("b");
console.log(foo[0]); //a
console.log(foo[1]); //b
console.log(foo.length); //2
foo.pop();
console.log(foo[0]); //a
console.log(foo[1]); //undefined
console.log(foo.length); //1
foo.unshift("z");
console.log(foo[0]); //a
console.log(foo[1]); //undefined
console.log(foo.length); //1
//////////////////////////

//Using JavaScript's type of operator to test for primitive types:
var myValue= [1,2,3];
console.log(typeof myValue === "string"); //false
console.log(typeof myValue === "number"); //false
console.log(typeof myValue === "undefined") //false
console.log(typeof myValue === "boolean"); //false
console.log(typeof myValue === "object") //true

//Using strict equality operator to check for null:
console.log(myValue === null); //false
</script>
 

728x90
반응형

'JS > JavaScript' 카테고리의 다른 글

[JS] 05. Conditional_Code  (0) 2017.08.28
[JS] 04. Operator  (0) 2017.08.28
[JS] 02. SyntaxBasic  (0) 2017.08.28
[JS] 01. Running code  (0) 2017.08.28
[JAVASCRIPT] JavaScript(자바스크립트) 이벤트  (0) 2017.08.01
'JS/JavaScript' 카테고리의 다른 글
  • [JS] 05. Conditional_Code
  • [JS] 04. Operator
  • [JS] 02. SyntaxBasic
  • [JS] 01. Running code
밍글링글링
밍글링글링
mingling - 밍글링, 밍글밍글링. 코드와 어우러지다. IT/ 프로그래밍/소스
    반응형
    250x250
  • 밍글링글링
    mingling
    밍글링글링
  • 전체
    오늘
    어제
    • 밍글링글링 (407) N
      • Flutter (2)
      • 일상생활 (8)
        • 리뷰 (1)
        • 생활정보 (4)
        • 맛집 (0)
        • 여행 (0)
        • 모든정보 (3)
      • JAVA (126)
        • 개념 (6)
        • 예제 (115)
        • Exception (2)
      • C (1)
        • C (1)
        • C++ (0)
        • C# (0)
      • JS (29)
        • JavaScript (18)
        • JQuery (5)
        • AJax (0)
        • NODE.JS (6)
        • Angular.JS 2.0 (0)
      • WEB (87)
        • HTML (6)
        • CSS (61)
        • JSP (20)
        • JSTL (0)
      • FrameWork (8)
        • Spring (8)
        • BootStrap (0)
        • MyBATIS (0)
        • JUnit (0)
      • 외부 라이브러리 (5)
      • 공유 소스 관리 (5)
        • Git (5)
        • SVN (0)
      • 빅데이터 프로그래밍 (37)
        • Python (37)
        • R Programming (0)
      • DB (7)
        • ORACLE (0)
        • MySql (6)
      • Development Tools (7)
        • StarUML (0)
        • eXERD (0)
        • Eclipse (4)
      • SKILL (6)
        • Migration (0)
        • Security (6)
      • MicroSoft (0)
        • Excel (0)
        • Word (0)
      • Android (0)
      • Server (21)
        • Ubuntu (5)
        • Linux (15)
      • IOS (0)
      • XML (0)
      • 미디어 (0)
      • 공지사항 (3)
      • NETWORK (1)
      • 게임 (4)
        • 피파 (1)
        • 리니지M (0)
        • 배틀그라운드 (1)
        • 듀랑고 (2)
      • 세상 이슈 (6)
      • 일렉트론 (0)
      • 대회 소식 (4)
      • 업무 (2)
      • Express, Vue (6)
      • docker (11)
      • svelte (3)
      • 블록체인 (1)
      • IT (10) N
      • Rust (0)
  • 블로그 메뉴

    • 홈
    • 태그
    • 미디어로그
    • 위치로그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    React Compiler
    Extension Bisect
    자바 객체 지향
    리눅스 설치
    css block
    jsp parameter
    티스토리 자동화
    Rust lang
    AI 코딩 에이전트
    VS Code 팁
    nginx ssl 설정
    mysql db
    Java Array
    css perspective
    vue cli
    자바 배열
    자바 생성자
    docker
    proxy pass
    java casting
    vue 설치
    css tb
    spring java
    ubuntu
    자바 exception
    러스트
    ssl 인증서 발급
    css list
    브라우저 자동화
    SSL 인증서
    API 설계
    rust linux
    Node
    자바 클래스
    클론코딩
    vscode
    css float
    svelte
    css transition
    gitlab 설치
    css table
    오류
    자바 for문
    프런트엔드
    에디터 팁
    nginx ssl 적용
    nginx
    servlet class
    jsp include
    lang rust
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
밍글링글링
[JS] 03. Type
상단으로

티스토리툴바