0% found this document useful (0 votes)
21 views

JS As A Programming Language

This document provides an overview of JavaScript as a programming language and compares it to C#. It discusses JavaScript's history and standardization, data types like numbers, strings, arrays, objects and functions. It also covers variable declaration, operators, and object-oriented programming concepts in JavaScript like constructors, inheritance and prototypes. The document demonstrates various JavaScript concepts through code examples.

Uploaded by

eugensabin
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

JS As A Programming Language

This document provides an overview of JavaScript as a programming language and compares it to C#. It discusses JavaScript's history and standardization, data types like numbers, strings, arrays, objects and functions. It also covers variable declaration, operators, and object-oriented programming concepts in JavaScript like constructors, inheritance and prototypes. The document demonstrates various JavaScript concepts through code examples.

Uploaded by

eugensabin
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

JavaScript

as a Programming Language
(Better than C#)
 
A little history
 JavaScript introduced in Netscape
version 2.0B3 December 1995
 JScript was included in Internet
Explorer 3.0, August 1996.
 ECMA script first edition June 1997
 ECMA script third edition December
1999
.NET framework
 Release dates of .net framework
 1.0 released at 2002/02/13
 2.0 released at 2005/11/07
 3.0 released at 2007/11/19
JavaScript Present and Future
 September 2008 Google released
Chrome browser
 http://v8.googlecode.com/svn/data/be
nchmarks/v2/run.html
 In 2010 Microsoft will release new
JavaScript implementation based on
DLR
 Work on 3.1 and 4.0 editions of the
standards continues
JavaScript is multi-paradigm language

 C like syntax (C# 1.0)


 Object Oriented (C# 1.0)
 Virtual Machine and GC (C# 1.0)
 Functional (C# 3.0)
 Dynamically Typed (C# 4.0)
Variables
Basic data types (value types)
 Numbers
 Strings
 Booleans
 undefined
Complex data types (reference
types)
 Array
 Object
 Function
Variable declaration
 Type of a variable is determined by
its value at run time not at compile
time
 var i=0;
 j=0; Don’t do this , always use var
Demo
 JS types
Numbers

Single numeric type, for integers and floating points numbers,


internally is 64 bit double
 345;
 34.5;
 3.45e2;
 0xFF;
 alert(0377) = ?
 alert(0.94 - 0.01)=?
 NaN
 Infinity
 -Infinity

Conversion:
 var i=Number(‘1’);
 ‘1’*1 also works
Strings
 Immutable
 build from 16 bit characters
 It possible to insert character by
Unicode escape codes
“A”==“\u0041”
 UCS-2, not quite UTF-16
Array
 Can have mix of values of any type
 JS arrays are sparse arrays
var arr=[];
arr[2]=1;
arr.length = ?
 JS arrays are growing dynamically
 Arrays are stacks push(obj,obj,..), pop()
 Arrays are queues shift(), unshift(obj,obj,..)
 Arrays also objects
arr[‘2’]= ?
Useful build in methods
 splice(start,toremove,obj,obj,…)
 sort(callback)
 slice(start,end)
 concat(arr1,arr2,arr3,…)
 join(separator)
Demo

Arrays
Function
 Have many similarities with objects.
 Acting as constructors for objects.
 Can be methods of an object
 Anonymous function (C# 2.0)
 Closures (C# 2.0)
Demo
 Functions
JavaScript and OOP
 No types == No classes
 Type of an object determined by its
behavior (Duck typing) (C# 4.0)
 Regular inheritance is not available (You
don’t need it)
 Constructors are optional (C# 3.0)
 All properties are public (But there is a
trick)
Object
 Type of an object is determined by its
value at run time. ( Dynamic Typing )
 var obj= {“x”:10,”test”:function(){return
this.x}};
 Objects are dictionaries:
 obj.x = 10 and obj["x"] = 10 are equivalent
 Properties and their values can be added,
changed, or deleted at run-time.
 delete obj.x
Constructors and this
 this makes sense only when it used
inside member methods of an
object.
 Any function can be constructor it
behavior change slightly when it
used as constructor
OOP in JavaScript
 Private methods
 Privileged methods
 Inheritance
 new f() produces new object inherited
from f.prototype
Demo
 Objects
Inheritance
 It’s not obvious that JS has
inheritance
 In JS, inheritance is based on
Prototype Chaining and not type
extension
Demo
 Inheritance
Small things
 a||’default’
 a&&a.value
 === , !==
 >> << Are slow

You might also like