SlideShare a Scribd company logo
JavaScript Introduction Aaron Conran Text: JavaScript The Definitive Guide By David Flannagan
Case Sensitive Example:  myVar  myVAr These are not the same variable.
(Optional) Semicolons JavaScript allows you to omit semicolons at the end of your statements. However this can create nasty bugs and cause difficult to debug problems. Use them at the end of statements and make your life easier.
Comments JavaScript supports both C and C++ style comments // this is a comment /* this is another comment */
Comments (JSDoc) Comments which begin with /** Note the 2 stars will be picked up by JSDoc JSDoc allows you to document your JavaScript classes in a formal manner similar to JavaDoc. Allows code and documentation to always be synchronized. For more information: http://jsdoc.sourceforge.net/
JavaScript Reserved Words Avoid the use of reserved words as variables and function names in your JavaScript.  For a full list Flanagan p19-20 Examples: break if switch in class
JavaScript DataTypes Numbers Strings Booleans Functions Objects Arrays null undefined Date Error
Numbers Integer (whole) Hexadecimal & Octal Floating-points (decimal) You can add, multiply divide and subtract numbers with their respective operator: +, *, /, & - The  Math  library of JavaScript also exposes a number of useful methods: Math.abs(num) Math.sin(num) Math.ceil(num) Full reference p 659-669
Special Numeric Values  (Table 3-1) p25 Special value to represent negative infinity Number.NEGATIVE_INFINITY Special value to represent infinity Number.POSTIVE_INFINITY Special not a number value Number.NaN Smallest (closest to zero) representable number Number.MIN_VALUE Largest representable number Number.MAX_VALUE Special not-a-number value NaN Special value to represent infinity Infinity Meaning Constant
Strings “ zero or more Unicode characters enclosed within single or double quotes” Examples: “” ‘ myForm’ “ testing” “ This is a longer string”
Escape Sequences To encode special values like new lines and ‘s in JavaScript strings you utilize a backslash Example: var menuText = ‘What\’s this?’;
Escape Sequences (Table 3-2) p27 The Latin-1 character specified by the octal digits XXX, between 1 and 377. Not support by ECMAScript v3; do not use this escpae sequence. \XXX The Unicode character specified by the four hexadecimal digits XXXX \uXXXX The Latin-1 character specified by the two hexadecimal digits XX \xXX Backslash (\u005C) \\ Apostrophe or single quote (u\0027) \’ Double quote (u\0022) \” Carriage return (u\000D) \r Form feed (\u000C) \f Vertical tab (\u000B) \v Newline (\u000A) \n Horizontal tab (\u0009) \t Backspace (\u0008) \b The NUL character (\u0000) \0 Character represented Sequence
Adding Strings You can also add (or concatenate) strings simply by adding them. Example: var anotherString = ‘new’; var newVariable = ‘Something ‘ + anotherString; When adding numbers they will automatically be converting to strings. Example: var x = 12; var newString = x + ‘ dozen eggs’;
Converting Strings To Numbers Utilize the parse Number  utility functions to extract numbers from strings. parseInt parseFloat Example: var x = “11”; var xNum = parseInt(x);
Booleans true (Other truthy values) 1 {} ‘ ‘  - space ‘ my String’ false (Other falsey values) undefined null 0 “” –  empty string
Equals vs Strictly Equals There is a strictly equals operator in JavaScript which will also check type as well as value. To show how this relates to boolean values: == Equals Works for Truthy values === Strictly Equals Works for truth only != Not Equals Works for Falsey values !== Strictly Not Equals Works for false only
Objects JavaScript Objects are similar to ColdFusion Structures. They consist of zero to many key-value pairs. They can be nested infinitely deep. They provide an associative array or hash map. Example: // using the Object constructor var newObj = new Object(); newObj.x = 10; newObj.y = 20; // OR using the Object literal syntax var newObj = {x: 10, y: 20};
Object Literal Object literal is the preferred way to create objects because it is concise and consistent with JSON-syntax. When utilizing object literal syntax key value pairs are separated by colon’s. Keys are called properties
Functions Functions are actually a datatype too Example: var myFn = function() {console.log(‘hi’);}; function myFn() {console.log(‘hi’);} These are 2 different ways of defining a similar function. There is also a Function constructor, however it’s use is limited because it can only create functions in the global scope.
Functions as Properties Properties of Objects can be any data type including Functions. Example: var myObject = {myFun: function() {console.log(‘hi’);}}; myObject.myFun();
Arrays Arrays can be defined using 2 syntaxes as well. Example: // Utilizing the Array constructor var myArray = new Array(); myArray[0] = 12; myArray[1] = 232; // OR using the Array literal syntax. var myArray = [12,232];
Arrays (cont.) Arrays can be infinitely nested Arrays can be sparse Arrays can store unlike datatypes Full reference available p 602-611 Arrays provide a number of useful properties and methods such as: length – property which defines how many elements are in the Array push – method which pushes another element on the Array when utilized as a Stack pop – method which pops an element off an Array when utilized as a Stack
null vs undefined null “ null  is a special keyword which indicates no value” undefined “ undefined  is returned when you use either a variable that has not been declared but never had a value assigned to it or an object property that does not exist”
null vs undefined Both of these equate to a  falsey  value. var myVar; // what is the value of myVar?

More Related Content

PDF
Quick python reference
PDF
Swift Study #3
PDF
Matlab strings
PPTX
JavaScript ES6 Fundamentals
PPT
Scala idioms
PDF
Java chapter 6 - Arrays -syntax and use
PDF
Real World Haskell: Lecture 3
PDF
Ms Ajax String And Object Extensions
Quick python reference
Swift Study #3
Matlab strings
JavaScript ES6 Fundamentals
Scala idioms
Java chapter 6 - Arrays -syntax and use
Real World Haskell: Lecture 3
Ms Ajax String And Object Extensions

What's hot (20)

PDF
Real World Haskell: Lecture 6
PDF
Effective PHP. Part 1
PDF
Effective PHP. Part 2
PPTX
Java script arrays
PDF
Strings in c language
PDF
Effective PHP. Part 5
DOC
Lesson 5
KEY
RFC4627 Reading
PPTX
The JavaScript Programming Language
PDF
Effective PHP. Part 3
PDF
Cross platform native development in f#
PDF
Scala Paradigms
PPTX
Complete Notes on Angular 2 and TypeScript
PDF
Real World Haskell: Lecture 2
PPTX
function, storage class and array and strings
PPTX
Data types in php
PDF
Suit case class
PPT
C# programming
PPTX
Mcai pic u 4 function, storage class and array and strings
Real World Haskell: Lecture 6
Effective PHP. Part 1
Effective PHP. Part 2
Java script arrays
Strings in c language
Effective PHP. Part 5
Lesson 5
RFC4627 Reading
The JavaScript Programming Language
Effective PHP. Part 3
Cross platform native development in f#
Scala Paradigms
Complete Notes on Angular 2 and TypeScript
Real World Haskell: Lecture 2
function, storage class and array and strings
Data types in php
Suit case class
C# programming
Mcai pic u 4 function, storage class and array and strings
Ad

Viewers also liked (8)

KEY
Introduction to javascript
PDF
Intro to JavaScript
PDF
8 introduction to_java_script
PPTX
Java script
PPT
Java script
PPTX
Session 3 Java Script
PPTX
What is Big Data?
PPTX
Big data ppt
Introduction to javascript
Intro to JavaScript
8 introduction to_java_script
Java script
Java script
Session 3 Java Script
What is Big Data?
Big data ppt
Ad

Similar to Java Script Introduction (20)

PPT
An introduction to javascript
PPTX
Front end fundamentals session 1: javascript core
PPTX
JavaScript.pptx
PPTX
03. Week 03.pptx
PDF
javascript objects
PDF
Js ch-1
PPTX
Chapter 1 .pptx
PPTX
Introduction to Client-Side Javascript
PDF
js_class_notes_for_ institute it is very useful for your study.pdf
PDF
Chapter 2: What's your type?
PDF
A Re-Introduction to JavaScript
PDF
GeoGebra JavaScript CheatSheet
PPT
Javascript
PDF
JavaScript introduction 1 ( Variables And Values )
PPTX
JavaScript Proven Practises
PPTX
Java script basics
PDF
Fewd week5 slides
PDF
JavaScript blast
PDF
Handout - Introduction to Programming
PPSX
Javascript variables and datatypes
An introduction to javascript
Front end fundamentals session 1: javascript core
JavaScript.pptx
03. Week 03.pptx
javascript objects
Js ch-1
Chapter 1 .pptx
Introduction to Client-Side Javascript
js_class_notes_for_ institute it is very useful for your study.pdf
Chapter 2: What's your type?
A Re-Introduction to JavaScript
GeoGebra JavaScript CheatSheet
Javascript
JavaScript introduction 1 ( Variables And Values )
JavaScript Proven Practises
Java script basics
Fewd week5 slides
JavaScript blast
Handout - Introduction to Programming
Javascript variables and datatypes

More from jason hu 金良胡 (20)

PPT
新员工培训
PDF
Javascript 闭包
PDF
Windows Powershell En
PDF
正则表达式
PDF
Work In Japan
PDF
Linuxcommand
PDF
PDF
Asp.Net运行时
PDF
PDF
PPT
Sql2005 Xml
PDF
Ms Ajax Dom Element Class
PDF
Ms Ajax Dom Element Class
PDF
Ms Ajax Number And Error Extensions
PDF
Ms Ajax Dom Event Class
PDF
Ms Ajax Date And Boolean Extensions
PDF
Ms Ajax Array Extensions
PPT
Ext Js Events
PPT
Ext Js Dom Navigation
PPT
Ext Js Events
新员工培训
Javascript 闭包
Windows Powershell En
正则表达式
Work In Japan
Linuxcommand
Asp.Net运行时
Sql2005 Xml
Ms Ajax Dom Element Class
Ms Ajax Dom Element Class
Ms Ajax Number And Error Extensions
Ms Ajax Dom Event Class
Ms Ajax Date And Boolean Extensions
Ms Ajax Array Extensions
Ext Js Events
Ext Js Dom Navigation
Ext Js Events

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Machine learning based COVID-19 study performance prediction
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
NewMind AI Monthly Chronicles - July 2025
Advanced methodologies resolving dimensionality complications for autism neur...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
Modernizing your data center with Dell and AMD
Dropbox Q2 2025 Financial Results & Investor Presentation
Machine learning based COVID-19 study performance prediction
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
A Presentation on Artificial Intelligence
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Network Security Unit 5.pdf for BCA BBA.
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Weekly Chronicles - August'25 Week I

Java Script Introduction

  • 1. JavaScript Introduction Aaron Conran Text: JavaScript The Definitive Guide By David Flannagan
  • 2. Case Sensitive Example: myVar myVAr These are not the same variable.
  • 3. (Optional) Semicolons JavaScript allows you to omit semicolons at the end of your statements. However this can create nasty bugs and cause difficult to debug problems. Use them at the end of statements and make your life easier.
  • 4. Comments JavaScript supports both C and C++ style comments // this is a comment /* this is another comment */
  • 5. Comments (JSDoc) Comments which begin with /** Note the 2 stars will be picked up by JSDoc JSDoc allows you to document your JavaScript classes in a formal manner similar to JavaDoc. Allows code and documentation to always be synchronized. For more information: http://jsdoc.sourceforge.net/
  • 6. JavaScript Reserved Words Avoid the use of reserved words as variables and function names in your JavaScript. For a full list Flanagan p19-20 Examples: break if switch in class
  • 7. JavaScript DataTypes Numbers Strings Booleans Functions Objects Arrays null undefined Date Error
  • 8. Numbers Integer (whole) Hexadecimal & Octal Floating-points (decimal) You can add, multiply divide and subtract numbers with their respective operator: +, *, /, & - The Math library of JavaScript also exposes a number of useful methods: Math.abs(num) Math.sin(num) Math.ceil(num) Full reference p 659-669
  • 9. Special Numeric Values (Table 3-1) p25 Special value to represent negative infinity Number.NEGATIVE_INFINITY Special value to represent infinity Number.POSTIVE_INFINITY Special not a number value Number.NaN Smallest (closest to zero) representable number Number.MIN_VALUE Largest representable number Number.MAX_VALUE Special not-a-number value NaN Special value to represent infinity Infinity Meaning Constant
  • 10. Strings “ zero or more Unicode characters enclosed within single or double quotes” Examples: “” ‘ myForm’ “ testing” “ This is a longer string”
  • 11. Escape Sequences To encode special values like new lines and ‘s in JavaScript strings you utilize a backslash Example: var menuText = ‘What\’s this?’;
  • 12. Escape Sequences (Table 3-2) p27 The Latin-1 character specified by the octal digits XXX, between 1 and 377. Not support by ECMAScript v3; do not use this escpae sequence. \XXX The Unicode character specified by the four hexadecimal digits XXXX \uXXXX The Latin-1 character specified by the two hexadecimal digits XX \xXX Backslash (\u005C) \\ Apostrophe or single quote (u\0027) \’ Double quote (u\0022) \” Carriage return (u\000D) \r Form feed (\u000C) \f Vertical tab (\u000B) \v Newline (\u000A) \n Horizontal tab (\u0009) \t Backspace (\u0008) \b The NUL character (\u0000) \0 Character represented Sequence
  • 13. Adding Strings You can also add (or concatenate) strings simply by adding them. Example: var anotherString = ‘new’; var newVariable = ‘Something ‘ + anotherString; When adding numbers they will automatically be converting to strings. Example: var x = 12; var newString = x + ‘ dozen eggs’;
  • 14. Converting Strings To Numbers Utilize the parse Number utility functions to extract numbers from strings. parseInt parseFloat Example: var x = “11”; var xNum = parseInt(x);
  • 15. Booleans true (Other truthy values) 1 {} ‘ ‘ - space ‘ my String’ false (Other falsey values) undefined null 0 “” – empty string
  • 16. Equals vs Strictly Equals There is a strictly equals operator in JavaScript which will also check type as well as value. To show how this relates to boolean values: == Equals Works for Truthy values === Strictly Equals Works for truth only != Not Equals Works for Falsey values !== Strictly Not Equals Works for false only
  • 17. Objects JavaScript Objects are similar to ColdFusion Structures. They consist of zero to many key-value pairs. They can be nested infinitely deep. They provide an associative array or hash map. Example: // using the Object constructor var newObj = new Object(); newObj.x = 10; newObj.y = 20; // OR using the Object literal syntax var newObj = {x: 10, y: 20};
  • 18. Object Literal Object literal is the preferred way to create objects because it is concise and consistent with JSON-syntax. When utilizing object literal syntax key value pairs are separated by colon’s. Keys are called properties
  • 19. Functions Functions are actually a datatype too Example: var myFn = function() {console.log(‘hi’);}; function myFn() {console.log(‘hi’);} These are 2 different ways of defining a similar function. There is also a Function constructor, however it’s use is limited because it can only create functions in the global scope.
  • 20. Functions as Properties Properties of Objects can be any data type including Functions. Example: var myObject = {myFun: function() {console.log(‘hi’);}}; myObject.myFun();
  • 21. Arrays Arrays can be defined using 2 syntaxes as well. Example: // Utilizing the Array constructor var myArray = new Array(); myArray[0] = 12; myArray[1] = 232; // OR using the Array literal syntax. var myArray = [12,232];
  • 22. Arrays (cont.) Arrays can be infinitely nested Arrays can be sparse Arrays can store unlike datatypes Full reference available p 602-611 Arrays provide a number of useful properties and methods such as: length – property which defines how many elements are in the Array push – method which pushes another element on the Array when utilized as a Stack pop – method which pops an element off an Array when utilized as a Stack
  • 23. null vs undefined null “ null is a special keyword which indicates no value” undefined “ undefined is returned when you use either a variable that has not been declared but never had a value assigned to it or an object property that does not exist”
  • 24. null vs undefined Both of these equate to a falsey value. var myVar; // what is the value of myVar?