Basic Java Script Syntax
19 flashcards · Programming Languages · by Antonio Anaya Tapia
Name at least three of the primitive data types in Javascript.
boolean, number, string
Name one non-primitive data type.
object
What is the difference between a function parameter and a function argument?
The parameters are the aliases for the values that will be passed to the function. The arguments are the actual values. var foo = function( a, b, c ) {}; // a, b, and c are the parameters foo( 1, 2, 3 ); // 1, 2, and 3 are the arguments
Write at least 3 of the comparison operators in Javascript.
===, >, <=
Name 3 keywords that can be used to declare a variable.
let const var
Create an array called `myArray`.
const myArray = [ ];
Create an object called `myObject`.
const myObject = {};
Write two functions: one using the `fat arrow` syntax and one using the `function` keyword syntax.
const func1 = () => {} const func2 = function() {}
Write a function that returns the number 5.
const func = () => { return 5; }
Write a function that takes two numbers and returns the sum of them.
const func = (num1, num2) => { return num1 + num2; }
Write a function that takes an array and returns the first index of the array.
const func = (array) => { return array[0]; }
Write function that takes an array of numbers and returns the sum of all of the numbers.
const func = (array) => { return array.reduce((a, b) => a + b, 0) }
Create an object with two properties and show two different ways to access them.
const myObject = { propertyOne: 1, propertyTwo: 2 } myObject.propertyOne; myObject[propertyTwo];
Create a function that takes two numbers and returns the number of times that the first number is divisible by the second number.
const func = (num1, num2) => { return Math.floor(num2 / num1); }
List three array methods.
map() reduce() includes()
In the case of the roman numeral converter when while (remainder) { for (i = 0; i < numbers.length; i++) { if (remainder >= numbers [i] ) { remainder -= numbers [i]; romanNumeralString += romanNumeralArray [i]; break } } } return romanNumaralString; } What does the break statement do ?
reset the loop to start at index 0 again
In the case of the roman numeral converter when while (remainder) { for (i = 0; i < numbers.length; i++) { if (remainder >= numbers [i] ) { remainder -= numbers [i]; romanNumeralString += romanNumeralArray [i]; break } } } return romanNumaralString; } What does the subtraction assignment (-=) do ?
subtracts the value of the right operand from a variable and assigns the result to the variable
In the case of the roman numeral converter when while (remainder) { for (i = 0; i < numbers.length; i++) { if (remainder >= numbers [i] ) { remainder -= numbers [i]; romanNumeralString += romanNumeralArray [i]; break } } } return romanNumaralString; } What does the addition assignment (+=) do ?
adds the value of the right operand to a variable and assigns the result to the variable
In the case of the rot13 problem function rot13(str) { /*The words are shifted from the 13th letter so A = N, B = O we create two strings that are defined as encoded which is the regular alphabet and decoded which is the shifted alphabet*/ let encoded = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' let decoded = 'NOPQRSTUVWXYZABCDEFGHIJKLM' //We use the replace method in order to replace all the decoded values into the decoded values, the key is to use a range of values a-z. return str.replace(/[a-z]/gi, letter…
you replace.(/[a-z]/gi, you replace a range of values in a global instance.