Types & Grammar: day 2

node v8.9.3
version: 1.0.0
endpointsharetweet
Arrays, ...
Arrays: containers for any type of value. No need to presize them; can keep adding elements. Interesting:
var array = []; array[0] = 1; array["yolomeister"] = 666; console.log(array["yolomeister"]); console.log("array length: " + array.length);
DOM query operations return lists of DOM elements. Function expose arguments object (array-like) to access them as a list.
function f(){ var array = Array.from(arguments); // var array = Array.prototype.slice.call(arguments); array.push("scanje"); console.log("after push: " + array); array.pop(); console.log("after pop: " + array); } f("drek","driska");
Strings: almost the same as arrays of characters.
var a = "kranken"; var b = ["k","r","a","n","k","e","n"]; a === b; //false var c = a.concat("wagen"); // "krankenwagen" var d = b.concat("w", "a"); // " ["k", ...] a[1] = "w"; // a = kranken b[1] = "w"; // b = k w a n.. a.map; //undefined a.join; //undefined // a.reverse(); //undefined b.reverse(); //working //quick'n'dirty, doesn't work for complex strings var zzz = a.split(""); zzz.reverse(); zzz.join();
Numbers: yay for only one type of numbers!
var a = 9.61992 console.log(a.toFixed(0)); console.log(a.toFixed(1)); console.log(a.toFixed(3)); // how many decimals 664..toFixed(2)
var a = 9.61992 console.log(a.toPrecision(3)); // how many digits console.log(0.1+0.2 == 0.3);
Loading…

no comments

    sign in to comment