SlideShare uma empresa Scribd logo
1 de 55
JavaScript Basics
Joar Gullestad Pettersen
JavaScript Data Types
String, Number, Boolean, Array, Object, Null, Undefined
Dynamic Types
• var x;
Dynamic Types
var x;

// x is: undefined
Dynamic Types
var x;

// x is: undefined

x = 5;

// x is set to a Number: 5
Dynamic Types
var x;

// x is: undefined

x = 5;

// x is set to a Number: 5

x = "Bond";

// x is changed to a String: "Bond"
Strings
var car = "Telsa Model S";
var car2 = 'Tesla Model S';
Numbers
• var x = 42;
• var y = 13.37;
• var z = 10e3;

// Written without decimals
// Written with decimals
// Exponential notation
Booleans
• var x = true;
• var y = false;
Array
var frukt = new Array();
frukt[0] = "eple";
frukt[1] = "banan";
frukt[2] = "pære";
["eple", "banan", "pære"]
Array 2
var frukt = new Array("eple", "banan", "pære");
["eple", "banan", "pære"]
Array 3
var frukt = ["eple", "banan", "pære"];
["eple", "banan", "pære"]
Array 4
• var frukt = ["eple", "banan", "pære"]
•
•
•
•

frukt.pop();

// ["eple", "banan"]

frukt.push("tomat");

// ["eple", "banan", "tomat"]

frukt.shift();

// ["banan", "tomat"]

frukt.unshift("tomat"); // ["tomat", "banan", "tomat"]
Objects
• Everything is an Object
Objects
•
•
•
•
•

Everything is an Object
Booleans can be objects or primitive data treated as objects
Numbers can be objects or primitive data treated as objects
Strings are also objects or primitive data treated as objects
Dates, Maths, Regular expressions, Arrays and functions are always objects
Object literal
An object is just a special kind of data,
with properties and methods.
var person = {
firstName: "John",
lastName: "Doe",
id: 5
};
Object literal
An object is just a special kind of data,
with properties and methods.
var person = {
firstName: "John",
lastName: "Doe",
id: 5
};
person.id; // 5
Object literal
An object is just a special kind of data,
with properties and methods.
var person = {
firstName: "John",
lastName: "Doe",
address: {

street: "Strandsvingen",
number: "14B"
}
};

person.address.street; // "Strandsvingen"
Functions
a block of code that will be executed when "someone" calls it:
function add(a, b) {
return a + b;
}
var add = function(a, b) {
return a + b;
}
Object Constructor
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
var randomPerson = new Person("John", "Doe");
Object
var randomPerson = new Object();
randomPerson.firstName = "John";
randomPerson.lastName = "Doe";
Boolean expressions
if (a == 2) {//if this is true
//do this...
}
Type coercion
• When JavaScript are unsure what you mean, It makes a guess
• Example:
if ('false') { alert("true"); }

• «A String is obviously not true or false, you probably
mean true!»
True! 
• if (true) { alert("true"); } // alerts "true"
• if ('false') { alert("true"); } // alerts "true"

• if ([]) { alert("true"); } // alerts "true"
• if (5) { alert("true"); } // alerts "true"

• if ({}) { alert("true"); } // alerts "true"
False 
• if (false) { alert("false"); } // does nothing
• if (0) { alert("false"); } // does nothing

• if (null) { alert("false"); } // does nothing
• if (undefined) { alert("false"); } // does nothing

• if ("") { alert("false"); } // does nothing
More type coercion 
1 == "1"
true == "1"
false == "0"
More type coercion 
1 == "1"
true
true == "1"
false == "0"
More type coercion 
1 == "1"
true
true == "1"

true
false == "0"
More type coercion 
1 == "1"
true
true == "1"

true
false == "0"
true
More type coercion
1 == "1"
true
true == "1"

true
false == "0"
true
false == "0" == 1 == true == [] == ""
More type coercion 
1 == "1"
true
true == "1"

true
false == "0"
true
false == "0" == 1 == true == [] == ""
true
Confusing?
• Solution?
Confusing?
• Solution?

• Avoid bugs| and use: ===
===
1 == true
true
1 === true
false
1 == "1"
true
1 === "1"
false
Scope & global variables
• C#/Java: anything inside curly brackets, {} , defines a scope
• Example:
if (true)

{

var scopeVariable = "Test";
}
scopeVariable = "Test2"; // variable not defined
Scope & global variables
• Javascript: only functions define a new scope
• Example:
if (true) {
var scopeVariable = "Test";
}
scopeVariable; // value: "Test";
Scope & global variables
function scope1() {
var member; //is a member of the scope defined by the function example
//this function is also part of the scope of the function example

var innerScope = function() {
member= 12; // traverses scope and assigns member in scope1 to 12
};
};
Scope & global variables
function scope1() {
var member; //is a member of the scope defined by the function example
//this function is also part of the scope of the function example

var innerScope = function() {
var member= 12; // defines member in this scope and do not traverse
};
};
Scope & global variables
function scope1() {
var member;

//is a member of the scope defined by the function example

//this function is also part of the scope of the function example
var bar = function() {
member= 12; // traverses scope and assigns scope1member.foo to 12
};
};
function scope2() {
member = 15; // traverses scope and assigns global.member to 15
}
Namespaces
• Not built into JavaScript
• Problem?
C# namespace
namespace Peanuts
{
}
JavaScript (Ad-hoc) namespace
var Peanuts = {};

// Object used as namespace
JavaScript (Ad-hoc) namespace
var Peanuts = Peanuts || {}; // in case it already
exists
C# Namespace
namespace Peanuts
{
public class Person
{
}
}
«Classes» and «methods» ?
var Peanuts = Peanuts || {};
Peanuts.Calculator = {
add: function (a,b) {
return a + b;

},
subtract: function () {
return a - b;
}
};

Peanuts.Calculator.add(1, 2); // 3
Immediately invoked function expressions
• (function () {
•
// logic/code here
• })();
Why?
• Executes an expression and therefore code immediately
• Creates «privacy» for your code (function scope ftw!)
How?
• JavaScript, parenthesis can’t contain statements.
• When the parser encounters the function keyword, it knows to
parse it as a function expression and not a function declaration.
Immediately invoked function expressions
•
•
•
•
•

(function () {
// logic/code here
})();
The key thing about JavaScript expressions is that they return values.
To invoke the function expression right away we just need to tackle a couple
of parentheses on the end(like above).
Immediately invoked function expressions
• (function ($) {
•
// logic/code here
• })(jQuery);
Revealing module pattern
var Peanuts = Peanuts || {};
Peanuts.Calculator = function () {
var add = function(a, b) {
return a + b;
};
var subtract = function(a, b) {

return a - b;
};
return {
add: add,
subtract: subtract
};
};

Peanuts.Calculator().add(1, 2); // 3
Revealing module pattern 2
var Peanuts = Peanuts || {};
Peanuts.Calculator = (function () {
var add = function(a, b) {
return a + b;

};
return {
add: add,
};
})();

Peanuts.Calculator.add(1, 2); // 3
Revealing module pattern 3
var Peanuts = Peanuts || {};
Peanuts.Calculator = (function () {
var PI = 3.14; // private variable!
var getCircleArea = function(r) {
return PI * r * r;

};
return {
getCircleArea: getCircleArea // public method
};
})();
Peanuts.Calculator.getCircleArea(2); // 12.56
Sources
• http://javascriptweblog.wordpress.com/2010/06/07/understandingjavascript-prototypes/

• www.w3schools.com
• http://www.youtube.com/watch?v=wOMLlEAqgRk
• http://designpepper.com/blog/drips/an-introduction-to-iifes-immediatelyinvoked-function-expressions

Mais conteúdo relacionado

Mais procurados

Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript BootcampAndreCharland
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Basic Javascript
Basic JavascriptBasic Javascript
Basic JavascriptBunlong Van
 
[A 3]Javascript oop for xpages developers - public
[A 3]Javascript oop for xpages developers - public[A 3]Javascript oop for xpages developers - public
[A 3]Javascript oop for xpages developers - publicKazunori Tatsuki
 
Contracts in-clojure-pete
Contracts in-clojure-peteContracts in-clojure-pete
Contracts in-clojure-petejessitron
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptAdieu
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptStoyan Stefanov
 
JavaScript 1 for high school
JavaScript 1 for high schoolJavaScript 1 for high school
JavaScript 1 for high schooljekkilekki
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and ArraysWebStackAcademy
 
Java best practices
Java best practicesJava best practices
Java best practicesRay Toal
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java ProgrammersMike Bowler
 

Mais procurados (20)

Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript Bootcamp
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Javascript
JavascriptJavascript
Javascript
 
Basic Javascript
Basic JavascriptBasic Javascript
Basic Javascript
 
[A 3]Javascript oop for xpages developers - public
[A 3]Javascript oop for xpages developers - public[A 3]Javascript oop for xpages developers - public
[A 3]Javascript oop for xpages developers - public
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
Clean code
Clean codeClean code
Clean code
 
Contracts in-clojure-pete
Contracts in-clojure-peteContracts in-clojure-pete
Contracts in-clojure-pete
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
 
JavaScript 1 for high school
JavaScript 1 for high schoolJavaScript 1 for high school
JavaScript 1 for high school
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
Java best practices
Java best practicesJava best practices
Java best practices
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Clean code slide
Clean code slideClean code slide
Clean code slide
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
 

Destaque

Working with Arrays in JavaScript
Working with Arrays in JavaScriptWorking with Arrays in JavaScript
Working with Arrays in JavaScriptFlorence Davis
 
Javascript - Array - Writing
Javascript - Array - WritingJavascript - Array - Writing
Javascript - Array - WritingSamuel Santos
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Shekhar Gulati
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM ManipulationsYnon Perek
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom ManipulationMohammed Arif
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays Reem Alattas
 
DOM ( Document Object Model )
DOM ( Document Object Model )DOM ( Document Object Model )
DOM ( Document Object Model )ITSTB
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOMMindy McAdams
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to ArraysTareq Hasan
 
DOM Features You Didn’t Know Existed
DOM Features You Didn’t Know ExistedDOM Features You Didn’t Know Existed
DOM Features You Didn’t Know ExistedFITC
 
TechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in DepthTechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in DepthTech CBT
 

Destaque (13)

Working with Arrays in JavaScript
Working with Arrays in JavaScriptWorking with Arrays in JavaScript
Working with Arrays in JavaScript
 
Javascript - Array - Writing
Javascript - Array - WritingJavascript - Array - Writing
Javascript - Array - Writing
 
Arrays
ArraysArrays
Arrays
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM Manipulations
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays
 
DOM ( Document Object Model )
DOM ( Document Object Model )DOM ( Document Object Model )
DOM ( Document Object Model )
 
Introduction to the DOM
Introduction to the DOMIntroduction to the DOM
Introduction to the DOM
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
DOM Features You Didn’t Know Existed
DOM Features You Didn’t Know ExistedDOM Features You Didn’t Know Existed
DOM Features You Didn’t Know Existed
 
TechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in DepthTechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in Depth
 

Semelhante a Javascript basics

JavaScript For CSharp Developer
JavaScript For CSharp DeveloperJavaScript For CSharp Developer
JavaScript For CSharp DeveloperSarvesh Kushwaha
 
Stuff you didn't know about action script
Stuff you didn't know about action scriptStuff you didn't know about action script
Stuff you didn't know about action scriptChristophe Herreman
 
Basics of Javascript
Basics of JavascriptBasics of Javascript
Basics of JavascriptUniverse41
 
DIWE - Programming with JavaScript
DIWE - Programming with JavaScriptDIWE - Programming with JavaScript
DIWE - Programming with JavaScriptRasan Samarasinghe
 
JavaScript Beginner Tutorial | WeiYuan
JavaScript Beginner Tutorial | WeiYuanJavaScript Beginner Tutorial | WeiYuan
JavaScript Beginner Tutorial | WeiYuanWei-Yuan Chang
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & AnswersRatnala Charan kumar
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyIgor Napierala
 
Douglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsDouglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsAjax Experience 2009
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascriptMD Sayem Ahmed
 

Semelhante a Javascript basics (20)

JavaScript For CSharp Developer
JavaScript For CSharp DeveloperJavaScript For CSharp Developer
JavaScript For CSharp Developer
 
Stuff you didn't know about action script
Stuff you didn't know about action scriptStuff you didn't know about action script
Stuff you didn't know about action script
 
JavaScript Bootcamp
JavaScript BootcampJavaScript Bootcamp
JavaScript Bootcamp
 
Basics of Javascript
Basics of JavascriptBasics of Javascript
Basics of Javascript
 
DIWE - Programming with JavaScript
DIWE - Programming with JavaScriptDIWE - Programming with JavaScript
DIWE - Programming with JavaScript
 
JavaScript Beginner Tutorial | WeiYuan
JavaScript Beginner Tutorial | WeiYuanJavaScript Beginner Tutorial | WeiYuan
JavaScript Beginner Tutorial | WeiYuan
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
 
Goodparts
GoodpartsGoodparts
Goodparts
 
Javascript status 2016
Javascript status 2016Javascript status 2016
Javascript status 2016
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
Short intro to ECMAScript
Short intro to ECMAScriptShort intro to ECMAScript
Short intro to ECMAScript
 
Wakanday JS201 Best Practices
Wakanday JS201 Best PracticesWakanday JS201 Best Practices
Wakanday JS201 Best Practices
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishy
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Douglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsDouglas Crockford Presentation Goodparts
Douglas Crockford Presentation Goodparts
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
Javascript
JavascriptJavascript
Javascript
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
 

Mais de Solv AS

Digitalization and improvements with robot technology (RPA)
Digitalization and improvements with robot technology (RPA)Digitalization and improvements with robot technology (RPA)
Digitalization and improvements with robot technology (RPA)Solv AS
 
BrilliantOffice
BrilliantOfficeBrilliantOffice
BrilliantOfficeSolv AS
 
Intranett og samhandling i skyen. Hvordan skape begeistring?
Intranett og samhandling i skyen. Hvordan skape begeistring?Intranett og samhandling i skyen. Hvordan skape begeistring?
Intranett og samhandling i skyen. Hvordan skape begeistring?Solv AS
 
"Hvordan sikre kunden i usikre tider"
"Hvordan sikre kunden i usikre tider" "Hvordan sikre kunden i usikre tider"
"Hvordan sikre kunden i usikre tider" Solv AS
 
Microsoft ignite 2015 update
Microsoft ignite 2015 updateMicrosoft ignite 2015 update
Microsoft ignite 2015 updateSolv AS
 
Bli kvitt møtehelvetet for det koster mer enn sykefraværet fra MyPocket.Academy
Bli kvitt møtehelvetet for det koster mer enn sykefraværet fra MyPocket.AcademyBli kvitt møtehelvetet for det koster mer enn sykefraværet fra MyPocket.Academy
Bli kvitt møtehelvetet for det koster mer enn sykefraværet fra MyPocket.AcademySolv AS
 
Hvordan skape engasjement og bygge kultur av Monica Eriksen
Hvordan skape engasjement og bygge kultur av Monica EriksenHvordan skape engasjement og bygge kultur av Monica Eriksen
Hvordan skape engasjement og bygge kultur av Monica EriksenSolv AS
 
Hvordan kapitalisere på ditt intranett av Pia Fischer
Hvordan kapitalisere på ditt intranett av Pia FischerHvordan kapitalisere på ditt intranett av Pia Fischer
Hvordan kapitalisere på ditt intranett av Pia FischerSolv AS
 
Peanuts story
Peanuts story Peanuts story
Peanuts story Solv AS
 
Peanuts TechEd North America 2014 Update
Peanuts TechEd North America 2014 UpdatePeanuts TechEd North America 2014 Update
Peanuts TechEd North America 2014 UpdateSolv AS
 
Nyheter fra SPC 2014 - Brilliant Breakfast
Nyheter fra SPC 2014 - Brilliant Breakfast Nyheter fra SPC 2014 - Brilliant Breakfast
Nyheter fra SPC 2014 - Brilliant Breakfast Solv AS
 
Sharepoint til mobile enheter på en sikker måte
Sharepoint til mobile enheter på en sikker måteSharepoint til mobile enheter på en sikker måte
Sharepoint til mobile enheter på en sikker måteSolv AS
 
Moderne intranett basert på SharePoint – Bologna Collaboration
Moderne intranett basert på SharePoint – Bologna CollaborationModerne intranett basert på SharePoint – Bologna Collaboration
Moderne intranett basert på SharePoint – Bologna CollaborationSolv AS
 
Hyper-V for dummies for VMware smarties
Hyper-V for dummies for VMware smartiesHyper-V for dummies for VMware smarties
Hyper-V for dummies for VMware smartiesSolv AS
 
Automatisert tjenestelevering med System Center
Automatisert tjenestelevering med System CenterAutomatisert tjenestelevering med System Center
Automatisert tjenestelevering med System CenterSolv AS
 
Farger, opacity og gradients
Farger, opacity og gradientsFarger, opacity og gradients
Farger, opacity og gradientsSolv AS
 
Endringsledelse - drevet av innovasjon og IT av Christian Rangen
Endringsledelse - drevet av innovasjon og IT av Christian Rangen Endringsledelse - drevet av innovasjon og IT av Christian Rangen
Endringsledelse - drevet av innovasjon og IT av Christian Rangen Solv AS
 
Endelig et intranett de ansatte liker - Ove Dalen
Endelig et intranett de ansatte liker - Ove DalenEndelig et intranett de ansatte liker - Ove Dalen
Endelig et intranett de ansatte liker - Ove DalenSolv AS
 
Moderne intranett basert på SharePoint - Bologna collaboration av Vikram og O...
Moderne intranett basert på SharePoint - Bologna collaboration av Vikram og O...Moderne intranett basert på SharePoint - Bologna collaboration av Vikram og O...
Moderne intranett basert på SharePoint - Bologna collaboration av Vikram og O...Solv AS
 
Alle mann til pumpene! Nytt ntranett på 90 dager av Frode Sandal
Alle mann til pumpene! Nytt ntranett på 90 dager av Frode SandalAlle mann til pumpene! Nytt ntranett på 90 dager av Frode Sandal
Alle mann til pumpene! Nytt ntranett på 90 dager av Frode SandalSolv AS
 

Mais de Solv AS (20)

Digitalization and improvements with robot technology (RPA)
Digitalization and improvements with robot technology (RPA)Digitalization and improvements with robot technology (RPA)
Digitalization and improvements with robot technology (RPA)
 
BrilliantOffice
BrilliantOfficeBrilliantOffice
BrilliantOffice
 
Intranett og samhandling i skyen. Hvordan skape begeistring?
Intranett og samhandling i skyen. Hvordan skape begeistring?Intranett og samhandling i skyen. Hvordan skape begeistring?
Intranett og samhandling i skyen. Hvordan skape begeistring?
 
"Hvordan sikre kunden i usikre tider"
"Hvordan sikre kunden i usikre tider" "Hvordan sikre kunden i usikre tider"
"Hvordan sikre kunden i usikre tider"
 
Microsoft ignite 2015 update
Microsoft ignite 2015 updateMicrosoft ignite 2015 update
Microsoft ignite 2015 update
 
Bli kvitt møtehelvetet for det koster mer enn sykefraværet fra MyPocket.Academy
Bli kvitt møtehelvetet for det koster mer enn sykefraværet fra MyPocket.AcademyBli kvitt møtehelvetet for det koster mer enn sykefraværet fra MyPocket.Academy
Bli kvitt møtehelvetet for det koster mer enn sykefraværet fra MyPocket.Academy
 
Hvordan skape engasjement og bygge kultur av Monica Eriksen
Hvordan skape engasjement og bygge kultur av Monica EriksenHvordan skape engasjement og bygge kultur av Monica Eriksen
Hvordan skape engasjement og bygge kultur av Monica Eriksen
 
Hvordan kapitalisere på ditt intranett av Pia Fischer
Hvordan kapitalisere på ditt intranett av Pia FischerHvordan kapitalisere på ditt intranett av Pia Fischer
Hvordan kapitalisere på ditt intranett av Pia Fischer
 
Peanuts story
Peanuts story Peanuts story
Peanuts story
 
Peanuts TechEd North America 2014 Update
Peanuts TechEd North America 2014 UpdatePeanuts TechEd North America 2014 Update
Peanuts TechEd North America 2014 Update
 
Nyheter fra SPC 2014 - Brilliant Breakfast
Nyheter fra SPC 2014 - Brilliant Breakfast Nyheter fra SPC 2014 - Brilliant Breakfast
Nyheter fra SPC 2014 - Brilliant Breakfast
 
Sharepoint til mobile enheter på en sikker måte
Sharepoint til mobile enheter på en sikker måteSharepoint til mobile enheter på en sikker måte
Sharepoint til mobile enheter på en sikker måte
 
Moderne intranett basert på SharePoint – Bologna Collaboration
Moderne intranett basert på SharePoint – Bologna CollaborationModerne intranett basert på SharePoint – Bologna Collaboration
Moderne intranett basert på SharePoint – Bologna Collaboration
 
Hyper-V for dummies for VMware smarties
Hyper-V for dummies for VMware smartiesHyper-V for dummies for VMware smarties
Hyper-V for dummies for VMware smarties
 
Automatisert tjenestelevering med System Center
Automatisert tjenestelevering med System CenterAutomatisert tjenestelevering med System Center
Automatisert tjenestelevering med System Center
 
Farger, opacity og gradients
Farger, opacity og gradientsFarger, opacity og gradients
Farger, opacity og gradients
 
Endringsledelse - drevet av innovasjon og IT av Christian Rangen
Endringsledelse - drevet av innovasjon og IT av Christian Rangen Endringsledelse - drevet av innovasjon og IT av Christian Rangen
Endringsledelse - drevet av innovasjon og IT av Christian Rangen
 
Endelig et intranett de ansatte liker - Ove Dalen
Endelig et intranett de ansatte liker - Ove DalenEndelig et intranett de ansatte liker - Ove Dalen
Endelig et intranett de ansatte liker - Ove Dalen
 
Moderne intranett basert på SharePoint - Bologna collaboration av Vikram og O...
Moderne intranett basert på SharePoint - Bologna collaboration av Vikram og O...Moderne intranett basert på SharePoint - Bologna collaboration av Vikram og O...
Moderne intranett basert på SharePoint - Bologna collaboration av Vikram og O...
 
Alle mann til pumpene! Nytt ntranett på 90 dager av Frode Sandal
Alle mann til pumpene! Nytt ntranett på 90 dager av Frode SandalAlle mann til pumpene! Nytt ntranett på 90 dager av Frode Sandal
Alle mann til pumpene! Nytt ntranett på 90 dager av Frode Sandal
 

Último

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 

Último (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 

Javascript basics

  • 2. JavaScript Data Types String, Number, Boolean, Array, Object, Null, Undefined
  • 4. Dynamic Types var x; // x is: undefined
  • 5. Dynamic Types var x; // x is: undefined x = 5; // x is set to a Number: 5
  • 6. Dynamic Types var x; // x is: undefined x = 5; // x is set to a Number: 5 x = "Bond"; // x is changed to a String: "Bond"
  • 7. Strings var car = "Telsa Model S"; var car2 = 'Tesla Model S';
  • 8. Numbers • var x = 42; • var y = 13.37; • var z = 10e3; // Written without decimals // Written with decimals // Exponential notation
  • 9. Booleans • var x = true; • var y = false;
  • 10. Array var frukt = new Array(); frukt[0] = "eple"; frukt[1] = "banan"; frukt[2] = "pære"; ["eple", "banan", "pære"]
  • 11. Array 2 var frukt = new Array("eple", "banan", "pære"); ["eple", "banan", "pære"]
  • 12. Array 3 var frukt = ["eple", "banan", "pære"]; ["eple", "banan", "pære"]
  • 13. Array 4 • var frukt = ["eple", "banan", "pære"] • • • • frukt.pop(); // ["eple", "banan"] frukt.push("tomat"); // ["eple", "banan", "tomat"] frukt.shift(); // ["banan", "tomat"] frukt.unshift("tomat"); // ["tomat", "banan", "tomat"]
  • 15. Objects • • • • • Everything is an Object Booleans can be objects or primitive data treated as objects Numbers can be objects or primitive data treated as objects Strings are also objects or primitive data treated as objects Dates, Maths, Regular expressions, Arrays and functions are always objects
  • 16. Object literal An object is just a special kind of data, with properties and methods. var person = { firstName: "John", lastName: "Doe", id: 5 };
  • 17. Object literal An object is just a special kind of data, with properties and methods. var person = { firstName: "John", lastName: "Doe", id: 5 }; person.id; // 5
  • 18. Object literal An object is just a special kind of data, with properties and methods. var person = { firstName: "John", lastName: "Doe", address: { street: "Strandsvingen", number: "14B" } }; person.address.street; // "Strandsvingen"
  • 19. Functions a block of code that will be executed when "someone" calls it: function add(a, b) { return a + b; } var add = function(a, b) { return a + b; }
  • 20. Object Constructor function Person(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } var randomPerson = new Person("John", "Doe");
  • 21. Object var randomPerson = new Object(); randomPerson.firstName = "John"; randomPerson.lastName = "Doe";
  • 22. Boolean expressions if (a == 2) {//if this is true //do this... }
  • 23. Type coercion • When JavaScript are unsure what you mean, It makes a guess • Example: if ('false') { alert("true"); } • «A String is obviously not true or false, you probably mean true!»
  • 24. True!  • if (true) { alert("true"); } // alerts "true" • if ('false') { alert("true"); } // alerts "true" • if ([]) { alert("true"); } // alerts "true" • if (5) { alert("true"); } // alerts "true" • if ({}) { alert("true"); } // alerts "true"
  • 25. False  • if (false) { alert("false"); } // does nothing • if (0) { alert("false"); } // does nothing • if (null) { alert("false"); } // does nothing • if (undefined) { alert("false"); } // does nothing • if ("") { alert("false"); } // does nothing
  • 26. More type coercion  1 == "1" true == "1" false == "0"
  • 27. More type coercion  1 == "1" true true == "1" false == "0"
  • 28. More type coercion  1 == "1" true true == "1" true false == "0"
  • 29. More type coercion  1 == "1" true true == "1" true false == "0" true
  • 30. More type coercion 1 == "1" true true == "1" true false == "0" true false == "0" == 1 == true == [] == ""
  • 31. More type coercion  1 == "1" true true == "1" true false == "0" true false == "0" == 1 == true == [] == "" true
  • 34. === 1 == true true 1 === true false 1 == "1" true 1 === "1" false
  • 35. Scope & global variables • C#/Java: anything inside curly brackets, {} , defines a scope • Example: if (true) { var scopeVariable = "Test"; } scopeVariable = "Test2"; // variable not defined
  • 36. Scope & global variables • Javascript: only functions define a new scope • Example: if (true) { var scopeVariable = "Test"; } scopeVariable; // value: "Test";
  • 37. Scope & global variables function scope1() { var member; //is a member of the scope defined by the function example //this function is also part of the scope of the function example var innerScope = function() { member= 12; // traverses scope and assigns member in scope1 to 12 }; };
  • 38. Scope & global variables function scope1() { var member; //is a member of the scope defined by the function example //this function is also part of the scope of the function example var innerScope = function() { var member= 12; // defines member in this scope and do not traverse }; };
  • 39. Scope & global variables function scope1() { var member; //is a member of the scope defined by the function example //this function is also part of the scope of the function example var bar = function() { member= 12; // traverses scope and assigns scope1member.foo to 12 }; }; function scope2() { member = 15; // traverses scope and assigns global.member to 15 }
  • 40. Namespaces • Not built into JavaScript • Problem?
  • 41.
  • 43. JavaScript (Ad-hoc) namespace var Peanuts = {}; // Object used as namespace
  • 44. JavaScript (Ad-hoc) namespace var Peanuts = Peanuts || {}; // in case it already exists
  • 46. «Classes» and «methods» ? var Peanuts = Peanuts || {}; Peanuts.Calculator = { add: function (a,b) { return a + b; }, subtract: function () { return a - b; } }; Peanuts.Calculator.add(1, 2); // 3
  • 47. Immediately invoked function expressions • (function () { • // logic/code here • })();
  • 48. Why? • Executes an expression and therefore code immediately • Creates «privacy» for your code (function scope ftw!)
  • 49. How? • JavaScript, parenthesis can’t contain statements. • When the parser encounters the function keyword, it knows to parse it as a function expression and not a function declaration.
  • 50. Immediately invoked function expressions • • • • • (function () { // logic/code here })(); The key thing about JavaScript expressions is that they return values. To invoke the function expression right away we just need to tackle a couple of parentheses on the end(like above).
  • 51. Immediately invoked function expressions • (function ($) { • // logic/code here • })(jQuery);
  • 52. Revealing module pattern var Peanuts = Peanuts || {}; Peanuts.Calculator = function () { var add = function(a, b) { return a + b; }; var subtract = function(a, b) { return a - b; }; return { add: add, subtract: subtract }; }; Peanuts.Calculator().add(1, 2); // 3
  • 53. Revealing module pattern 2 var Peanuts = Peanuts || {}; Peanuts.Calculator = (function () { var add = function(a, b) { return a + b; }; return { add: add, }; })(); Peanuts.Calculator.add(1, 2); // 3
  • 54. Revealing module pattern 3 var Peanuts = Peanuts || {}; Peanuts.Calculator = (function () { var PI = 3.14; // private variable! var getCircleArea = function(r) { return PI * r * r; }; return { getCircleArea: getCircleArea // public method }; })(); Peanuts.Calculator.getCircleArea(2); // 12.56
  • 55. Sources • http://javascriptweblog.wordpress.com/2010/06/07/understandingjavascript-prototypes/ • www.w3schools.com • http://www.youtube.com/watch?v=wOMLlEAqgRk • http://designpepper.com/blog/drips/an-introduction-to-iifes-immediatelyinvoked-function-expressions