Top Banner
JavaScript Training Goal Trainers Format Lecture Exercises Ask Questions! bitovi/js-trainin
24

Types, Operators and Primitives

Aug 17, 2015

Download

Technology

alexisabril
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Types, Operators and Primitives

JavaScript Training

Goal Trainers Format

• Lecture• Exercises• Ask Questions!• bitovi/js-training

Page 2: Types, Operators and Primitives

Data Types, Operators and Primitives

Page 3: Types, Operators and Primitives

Undefined undefined Null null Boolean true String "hello" Number 2 Object {name: "value"} Array [1,2,3] Date new Date() RegExp /.*/g, Function function(){}

Data Types

Primitive

Object

Page 4: Types, Operators and Primitives

varnewassignment

deletemember

call

comparison

Operators

var foonew Foofoo = {bar: "a value"}foo.bar = valuedelete foo.barfoo.barfoo["bar"]bar()foo.bar()=====

Page 5: Types, Operators and Primitives

var me = { name: {first: "justin"} },

name = me.name;

name = {first: "alexis"};

me.name.first // justin

Page 6: Types, Operators and Primitives

WINDOWAddress Value

…. ….

x1001

x1002

x1003

x1004

…. ….

x2001

x2002

x2003

x2004

var str = "hi";

Page 7: Types, Operators and Primitives

var str = "hi";

Address Value

…. ….

x1001 call-object

x1002

x1003

x1004

…. ….

x2001

x2002

x2003

x2004

WINDOW

"hi"

Page 8: Types, Operators and Primitives

Address Value

…. ….

x1001 call-object

x1002

x1003

x1004

…. ….

x2001 STRING

x2002 2

x2003 hi

x2004

"hi"

WINDOW

var str = "hi";

Page 9: Types, Operators and Primitives

Address Value

…. ….

x1001 call-object

x1002

x1003

x1004

…. ….

x2001 STRING

x2002 2

x2003 hi

x2004

str "hi"

WINDOW

var str = "hi";

Page 10: Types, Operators and Primitives

"hi"str

Address Value

…. ….

x1001 call-object

x1002 str

x1003 -----

x1004

…. ….

x2001 STRING

x2002 2

x2003 hi

x2004

WINDOW

var str = "hi";

Page 11: Types, Operators and Primitives

var str = "hi";

Address Value

…. ….

x1001 call-object

x1002 str

x1003 2001

x1004

…. ….

x2001 STRING

x2002 2

x2003 hi

x2004

"hi"str

WINDOW

Page 12: Types, Operators and Primitives

var obj = {};obj.txt = "hi";

Address Value

…. ….

x1001

x1002

x1003

…. ….

x2001

x2002

x2003

x2004

…. ….

x2101

x2102

x2103

WINDOW

Page 13: Types, Operators and Primitives

var obj = {};obj.txt = "hi";

Address Value

…. ….

x1001 call-object

x1002

x1003

…. ….

x2001

x2002

x2003

x2004

…. ….

x2101

x2102

x2103

WINDOW

Page 14: Types, Operators and Primitives

var obj = {};obj.txt = "hi";

Address Value

…. ….

x1001 call-object

x1002

x1003

…. ….

x2001 OBJECT

x2002 0

x2003

x2004

…. ….

x2101

x2102

x2103

WINDOW

Page 15: Types, Operators and Primitives

var obj = {};obj.txt = "hi";

Address Value

…. ….

x1001 call-object

x1002 obj

x1003 -----

…. ….

x2001 OBJECT

x2002 0

x2003

x2004

…. ….

x2101

x2102

x2103

obj

WINDOW

Page 16: Types, Operators and Primitives

var obj = {};obj.txt = "hi";

Address Value

…. ….

x1001 call-object

x1002 obj

x1003 -----

…. ….

x2001 OBJECT

x2002 0

x2003

x2004

…. ….

x2101

x2102

x2103

obj

WINDOW

Page 17: Types, Operators and Primitives

var obj = {};obj.txt = "hi";

Address Value

…. ….

x1001 call-object

x1002 obj

x1003 x2001

…. ….

x2001 OBJECT

x2002 0

x2003

x2004

…. ….

x2101

x2102

x2103

"hi"

obj

WINDOW

Page 18: Types, Operators and Primitives

var obj = {};obj.txt = "hi";

Address Value

…. ….

x1001 call-object

x1002 obj

x1003 x2001

…. ….

x2001 OBJECT

x2002 0

x2003

x2004

…. ….

x2101 STRING

x2102 2

x2103 hi

"hi"

obj

txt

WINDOW

Page 19: Types, Operators and Primitives

var obj = {};obj.txt = "hi";

"hi"

obj

txt

Address Value

…. ….

x1001 call-object

x1002 obj

x1003 x2001

…. ….

x2001 OBJECT

x2002 1

x2003 txt

x2004 x2101

…. ….

x2101 STRING

x2102 2

x2103 hi

WINDOW

Page 20: Types, Operators and Primitives

delete

var me = { name: { first:"justin" } }, name = me.name;

delete me.name;

name.first //-> "Justin"

WINDOW

name

name

"justin"

me

first

Page 21: Types, Operators and Primitives

typeof

Type Result

Undefined "undefined"

Null "object"

Boolean "boolean"

Number "number"

NaN "number"

String "string"

Function "function"

Array "object"

Any other object

"object"

Page 22: Types, Operators and Primitives

Summary

Variables are put in a call object.

var me;

= sets a variable or property to point somewhere in memory.

me = {};me.age = 30;

WINDOW

me

30

age

Page 23: Types, Operators and Primitives

var me = { name: { first:"justin" } }, name = me.name;

name = { first:"alexis"};

me.name.first

Understanding

WINDOW

name

"alexis"first

name

"justin"

me

first

Page 24: Types, Operators and Primitives

var me = { name: { first:"justin" } }, name = me.name;

name = { first:"alexis"};

me.name.first

Understanding

WINDOW

name

"alexis"first

name

"justin"

me

first