GoConqr has a new look! Let us know what you think.

Flashcards

Javascript

D F English 49 cards

Cards in this deck (49)

  1. 1return character at a certain index string = "Hello";charAt();
    example: string.charAt(0);
    returns "H"
    JS global variable
  2. 2returns the index of first occurrence of a string string = "Hello"indexOf();
    example: string.indexOf("H");
    returns 0 (-1 if no match)
  3. 3returns a specified part of a string between two indexes string = "Hello"slice();
    string.slice(1); returns "H"
    or string.slice(1,3); returns "He"
    note that it only goes up to the last arg, not including it
  4. 4concatenate/join two strings to another string1 = "Hello" string2 = "today"concat();
    string1 = string1.concat(" ", string2);
    returns "Hello today";
  5. 5check if a string ends with a specified stringendsWith();
    string.endsWith("Deb");
  6. 6check if a string contains a substringincludes();
    string.includes("Hello");
  7. 7check if a regexp is in a string and return first or each of the matches in an arraymatch();
    string.match(/\nHello/g);
    returns [Hello,Hello,Hello] if there are 3
    use /g to return all of them
  8. 8repeat a string the specified number of timesrepeat();
    string.repeat(2);
    returns "HelloHello"
  9. 9breaks a string into an array of substringssplit();
    string.split("e");
    strings are split by whatever is the arg
    returns ["H","llo"]
  10. 10convert to a string object var foo = 3;toString();
    foo.toString();
    returns "3"
  11. 11convert to uppercase and to lowercasetoUpperCase();
    toLowerCase();
  12. 12remove whitespace from both ends of a stringtrim();
    " Hello ! "
    converts to "Hello !"
  13. 13return the number of characters in a stringlength();
    for string = "Hello!"
    string.length(); returns 6
  14. 14replace one string or substring with anotherreplace();
    something.replace("Hello","Tsup");
    replace the first arg with second arg
  15. 15return the first index of the argsearch();
    for string = "Hello"
    string.search(/ell/); returns 1
  16. 16check if a number is an integernum.isInteger();
  17. 17converts a number to one with specified # of digits after the decimalnum.toFixed(2);
  18. 18converts a number to one with specified # of digits TOTALnum.toPrecision(3);
  19. 19check if a number is finite or not. what are infinite nums?num.isFinite();
    infinite nums are repeating decimals, NaN, or infinity
  20. 20if condition is met, then set the variable to first thing, or else set it to the last thingvarName = (condition) ? "value" : "value2"
    ex: barStatement = (age > 21) ? "Have a beer!" : "No alcohol!"
    known as ternary operator
  21. 21what is truthy and falsy?they evaluate as truth or false in a boolean statement, even if they are not actual false.
  22. 22what falsy values are not actually false?NaN, null, undefined, 0, ""
  23. 23What can be an object type and what can't?everything that is not a primitive type (string, number, boolean, null/undefined).
    includes arrays and hashes.
  24. 24What does it mean that JS variables are untyped?You can assign a variable a value of one type (eg true, which is boolean), and then reassign it a value of another type (eg "hello", which is a string).
  25. 25What does an object have?It has a collection of properties, and each property has a name-value pair. (huh?)
  26. 26What are the primitive types, and how are they different from object types?String, number, boolean, null/undefined.
    They have values, whereas object types have properties (which in turn have name/value pairs).
  27. 27What are the two ways to create objects?Literal notation and constructor notation
  28. 28What is literal notation? What is it useful for?Puts all the properties right into the object variable declaration. It has a { after the =.
    var myObject = { firstProp: ‘something’, secondProp: 40 };
    Useful for one-off object creation.
  29. 29What is constructor notation? What is this useful for?Requires the use of "new" to create the object variable, then use .notation or []notation to separately create the properties and methods.
    Useful for creating many objects as if from a template.
  30. 30return the type of a variable, object, function or expressiontypeof
    "hello" typeof String
  31. 31what can the typeof operator not do?it can't tell if something is a Date or an Array
  32. 32Determine is something is an instance of a larger objectinstanceOf
    cars instanceOf Array
  33. 33What can instanceOf be used for?Array, Object, String, Number, or a constructor of some kind
  34. 34When is a variable that is part of an object variable? What forms does it come in?Property
    Key/value or name/value
  35. 35What is a function that is a part of an object variable?Method
  36. 36What is the difference between key/value and name/value?They mean essentially the same thing.
    Name/value is with = signs.
    Key/value is with : signs.
  37. 37Example of creating an object with literal notation?var hotel = {
    name: 'Quay', rooms: 40, checkAvailability: function(){ dosomething;}
    }
  38. 38Example of constructor notation?function Hotel(name, rooms, booked){ this.name = name;
    this.rooms = rooms;
    this.booked = booked;
    checkAvailability = function(){
    dosomething ;
    };
    }
    create a new object like: new Hotel(‘Deb Hotel’, 40, 22);
  39. 39How can you tell if something is a constructor and not a normal function?It is capitalized.
  40. 40How can you access an object's properties and methods?Use dot notation (preferred) or bracket notation.
  41. 41Example of dot notation and what it's used for?var hotelName = hotel.name;
    used to access an object's properties
  42. 42Example of bracket notation and what it's used for?var hotelName = hotel['name'];
  43. 43Example of arrays in an object?costsObject = { room1:[42,23,3], room2:[52,62,5] };
  44. 44Example of objects in an array?costsArray = [ {accom: 420, food: 40, phone: 10}, {accom:520, food:42, phone:20} ];
  45. 45Example of how you can you access the values of arrays in an object?costsObject.room2[0];
    Given:
    costsObject = { room1:[42,23,3], room2:[52,62,5] };
    Returns 52
  46. 46Example of how you can acccess the values of objects in an array:costsArray[0].food;
    Given:
    costsArray = [ {accom: 420, food: 40, phone: 10}, {accom:520, food:42, phone:20} ];
    returns 40
  47. 47What is the difference between null and undefined?Technically they can be used interchangeably, but null tends to mean the absence of something and undefined refers more to errors (and / by 0).
  48. 48Why is JS terrible at calculations?It uses binary-floating point numbers, which approximates values but doesn't always get them right due to rounding erros (so .3 - .2 doesn't equal exactly .1).
  49. 49What is a workaround for the binary-floating point number problem in JS?Using scaled integers (?)

Information

Description
Flashcards on Javascript, created by D F on 21/11/2017.
Created by
D F
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?