javascript: memory, passing, and objectscs115/slides/w06-04-objectsvalidation.pdf · • javascript...
TRANSCRIPT
JavaScript:Memory,Passing,andObjects
CS115ComputingfortheSocio-TechnoWebBrianBrubach
JavaScript“Primitive”DataTypes
• string• number• booleanà trueorfalse• null• undefined• symbol
JavaScript“Primitive”DataTypes
• Imagineavariableforaprimitivetypestoresthevalue(simplificationofwhatreallyhappens)
var x = “word”;
var y = 12;
someFunction(x, y);
• ThefunctionsomeFunction receivesthevalues“word”and12• LocalvariablesdefinedbyparametersinsomeFunction havethesevalues• Alteringthoselocalvariableswillnotaffecttheglobalvariablexandy
• JavaScriptuses“passbyvalue”• Valueofavariablepassestoafunction• Thealternative,“passbyreference”,wouldpassthevariablesthemselves
function someFunciton(hot, cold){var warm = hot + cold;return warm;
}
Arrays(andOtherObjects)
• Storedandhandleddifferentlythanprimitives• Imaginethevariablestoresonlytheaddress ofwherethearrayisactuallystored
var z = [“dog”, “cat”, “bee”];
document.write(z[1]); // Prints “cat”
document.write(z.length) // Prints “3”
• Supposezstorestheaddressofablockinmemory• Canimaginez=<someAddress>
“dog” “cat” “bee”0 1 2
3length
Location:<someAddress>Blockofmemorystoringthe
arraythatzpointstoorrefersto
PassingArrays(andOtherObjects)intoFunctions
var z = [“dog”, “cat”, “bee”]; // stored at <someAddress>
someFunction(z);
• ThefunctionsomeFunction receivestheaddress<someAddress>of• LocalvariabledefinedbyparameterinsomeFunction hastheaddress<someAddress>
• someFunction cannotchangewhichaddresszpointsto• someFunction canchangethearrayatthataddress
// Change z to [“dog”, praying mantis”, “bee”]
function someFunction(animals) {
animals[1] = “praying mantis”;
}
Null
• Representsnovalue• Representsnoaddress• Canassignit
var a = null;
NullversusUndefined
• null• Cndicates novalue• Canbereturnedbyfunctions
• undefined• Valueassociatedwithuninitializedvariables• var x;• Whenafunctionthatisexpectedtoreturnavaluedoesnotreturnone(IMPORTANTcase)
• Valueassociatedwithobjectpropertiesthatdonotexist
• ==considersnullandundefinedequal• ===considersnullandundefineddifferent
• Rememberusing===and!==isbestpractice
NaN
• NaNà Not-A-Number(SameasNumber.NaN)• Unequaltoanynumberincludingitself• UseisNaN functionà determines(returnstrueorfalse)whetheranargumentisnotanumber.Itattemptstoconverttheargumenttoanumber
• Thefollowingcomparisonsreturnfalse• NaN ==NaN• NaN ===NaN
• Theopposite:!isNaN()allowustodeterminewhetheranexpressionisanumber
• Notice:isNaN(20)à False• YoumaywanttowriteafunctioncallisNumber thatreturns!isNaN(x)
WebDataValidationandMoreonSources
Moreonsources
• Beawareofnon-peer-reviewedvenues• Includespreprintslikearxiv
• Googletoseeifjournalisreputable• Citetheconference/journal,notthepublisher• Examplesofpublishersorsearchtools
• WileyOnlineLibrary• SpringerLink• sciencedirect• Sagepublications• Googlescholar• ACMDigitalLibrary
IronicWikipediaPage
• https://en.wikipedia.org/wiki/Data_validation (accessed4-25-19)
Webliteracyresource
• https://webliteracy.pressbooks.com/front-matter/web-strategies-for-student-fact-checkers/
• Somecontentfromdesigner/developerJohnBrieger’s blogpost:http://johnbrieger.com/blog/?p=321 (accessed4-25-19)
A TaleoftheBoardGameRisingSunandKōtahi
ATaleoftheBoardGameRisingSunandKōtahi
• ThemeofgameisJapaneseMythology• Designer’spriorgamewasaboutNorseMythology
• Verysuccessfulgamefrompubliclytradedcompany• Kickstartercampaignselling30k+copiesandrevenueover$4million• SoldtensofthousandsmoreaftertheKickstarter• AvailableatBoard&Brewnextdoor
• April4th,2017à Kickstarterends(expecteddeliveryin2018)• January21st,2018à Afanasks,“WhatisKōtahi?”
WhatisKōtahi?
• TheonlyinformationtobefoundisontheWikipediapage"ListoflegendarycreaturesfromJapan”
• AccordingtoMaoriDictionary,Kotahimeans“one”orasenseoftogetherness• ButtheMaoripeopleliveinNewZealandnotJapan
• Someonesearchedtheotherunfamiliarwords“ManawaBradford”…
WhatisKōtahi?
• Kotahi-ManawaBradfordisafarmerinNewZealand• Friendsmakefunofhimforbeinghairyandgettingangrywhileplayinggames• OnefriendmadeafakeWikipediaeditasajoke• ThedesignerofRisingSun(whoisbrilliantandhard-working)usedWikipediaasreferencewithoutchecking
AnArtist’sRenderingofKōtahi
• AppearedonNewZealandnews• Thecompanysenthimafreeautographedgame
• Hehasaplasticfigurineofhisfriends’insidejokeabouthim• Moral:Don’ttrustWikipediaforresearch,butdouseitforjokes?
OutcomefortheRealKotahi
CheckingWikipediaEdits
• CancheckaWikipediapage’sedithistorybyclicking“Viewhistory”inthetoprightcornerofthepage• Showsyouwhomadeedits,whatthechangeswere,andwhen
• HereisoneeditforKōtahi• https://en.wikipedia.org/w/index.php?title=List_of_legendary_creatures_from_Japan&diff=next&oldid=738160684
• Theychanged“getsreallyangry”to“getsengulfedinrage”
• Warning:SomebogusWikipediaeditsaredisgusting,hateful,offensive,etc.• Luckily,abot,ClueBot NG,catchesmanyoftheseanddeletesthemfairlyquickly,buttheyareloggedintheedithistory
CriteriatoEvaluateWebData
• Authorship• Whowrotethedocument?• Doyourecognizetheauthor(e.g.,someoneinyourfield)?• Isthedocumentlinkedtoadocumentyoutrust?• Isbiographicalinformationprovided?• Istheauthorreferredtobyatrustauthority(persons)?
• PublishingEntity• Anyorganizationnameprovidedinthedocument?• Canyoucontactthewebmaster?• Anydocumentparts(headers,images,etc.)associatedwithanorganization?• IstheURLassociatedwithanorganizationyoutrust?• Canyouverifytheidentityoftheserverviawhois serversordnslookup?• Howaretheyfundedorwhatistheirrevenuemodel?
• Pointofview– Examinewhoisprovidingtheinformationandwhatmightbetheirpointofview• Isitpartofanorganizationwithaphilosophicalorpoliticalagenda?
CriteriatoEvaluateWebData
• Contextauthorsituatesthework• Authordisplaysknowledgeorsources,theories,techniques• Documentincludesabibliography
• Accuracy• Documentreliesonsourceslistedinabibliography• Backgroundinformationusedcanbeverifiedforaccuracy• Methodologypresentedisappropriateforthetopicandallowsforstudyduplication
• Currency(TimelinessofInformation)• Keepinmindthatforsomedocumentsthisisnotanissue• Documentreferstoclearlydatedinformation• Documentincludesapublicationdate
• Guidetoevaluatingwebpages(sourcesformostofthiscontent)• https://guides.library.jhu.edu/evaluate/internet-resources• http://guides.lib.berkeley.edu/evaluating-resources
WebSiteValidation(whois servers)
• Importanceoffindingownerofwebsite• http://www.dhmo.org/• Googledhmo.org authorTomWay
• Whois servers databasesthatkeeptrackofownersofdomains• https://www.whois.com/whois/
• Typedomain:umd.edu• YougetlotsofvalidcontactinfobecauseUMDislegit