Single Choice Question

  1. If we need to convert a variable call str which value is "12" to number 12, which way cannot do this job?
    1. parseInt(str)
    2. Number(str)
    3. +str
    4. !!str
  2. What is the result of the code:
                    
                        let num = 255;
                        alert(num.toString(16));
                    
                
    1. 255
    2. 'ff'
    3. NaN
    4. '255'
  3. Which following expression is true?
    1. 0.1 + 0.2 === 0.3
    2. !!4
    3. true + 1 > 2
    4. '120' > '13'
  4. What is the result of the code:
                    
                        let num = 0.125 + 0.124;
                        alert(+num.toFixed(2));
                    
                
    1. 0.25
    2. '0.249'
    3. '0.25'
    4. 0.249
  5. What is the result of the code: parseInt('1.8em') ?
    1. NaN
    2. 1.8
    3. 1
    4. 2
  6. To get the integer part of a float number: num (For example: get 12 from 12.8), which method can be used?
    1. Math.round(num)
    2. Math.abs(num)
    3. Math.floor(num)
    4. Math.ceil(num)
  7. To get the random integer between 20 and 30, which method can be used?
    1. Math.round(Math.random() * 10) + 20
    2. Math.round(Math.random() * 30)
    3. Math.round(Math.random() * 10 + 20)
    4. Math.random() * 30
  8. What is the result of the code:
                    
                        let fruits = ["Apple", "Orange", "Plum"];
                        alert(fruits[3]);
                    
                
    1. "Plum"
    2. "Orange"
    3. undefined
    4. throw an error
  9. To get the last element of array, which method can be used?
    1. array[array.length - 1]
    2. array[array.length]
    3. array[-1]
    4. array[array.len() - 1]
  10. To get the last element of array, which method can be used?
                    
                        let arr = [1,3,3,2,1,1,5];
                        console.log(Array.from(new Set(arr)));
                    
                
    1. [1,3,2,5]
    2. [1,3,3,2,1,1,5]
    3. [1,5]
    4. [1,3,3,2]
  11. Which way is not the correct way to express a string?
    1. 'hello'
    2. "hello"
    3. `hello`
    4. /hello/
  12. To get the last element of array, which method can be used?
                    
                        str = `Hello`;
                        alert(1 + str.length + str[0]);
                    
                
    1. '5H'
    2. '6H'
    3. '15H'
    4. '150'
  13. Which following option is belong to the primitive types?
    1. Number
    2. Array
    3. Object
    4. Function
  14. Which following option is belong to the composite types?
    1. Number
    2. String
    3. Boolean
    4. Function
  15. Which result of the following code is correct?
                    
                        function sum(a, b) {
                          return a + b;
                        }
    
                        alert(`1 + 2 = ${sum(1, 2)}.`);
                    
                
    1. '1 + 2 = 3.'
    2. '1 + 2 = ${sum(1, 2)}.'
    3. '1 + 2 = (1, 2)).'
    4. '1 + 2 = function.'
  16. Which is correct result of the code: 'Interface'.toUpperCase()?
    1. 'Interface'
    2. 'iNTERFACE'
    3. 'interface'
    4. 'INTERFACE'
  17. To justify whether the string 'Hello' contains 'e', which method can be used?
    1. 'Hello'.indexOf('e') >= 0
    2. 'Hello'.contains('e')
    3. 'Hello'.has('e')
    4. 'Hello'.substring(1,2) === 'e'
  18. To get the part of a string "stringify", which result is not "ring" ?
    1. str.substring(2, 6)
    2. str.substring(6, 2)
    3. str.slice(2, 6)
    4. str.slice(6, 2)
  19. Which result of the following code is correct?
                    
                        let fruits = ["Apple", "Orange", "Pear"];
                        fruits.pop();
                        alert(fruits);
                    
                
    1. ["Apple", "Orange", "Pear"]
    2. ["Apple", "Orange"]
    3. ["Orange", "Pear"]
    4. []
  20. Which result of the following code is correct?
                    
                        let arr = [1, 2, 3, 4, 5];
                        let result = arr.reduce((sum, current) => sum + current, 0);
                        alert(result);
                    
                
    1. 15
    2. 5
    3. 1
    4. 120
  21. Which result of the following code is correct?
                    
                        let user = {
                          name: "John",
                          age: 30
                        };
                        alert(Object.keys(user));
                    
                
    1. [["name", "John"], ["age", 30]]
    2. ["name", "John", "age", 30]
    3. ["John", 30]
    4. ["name", "age"]
  22. To get the day of month, we may use which method?
    1. getDate()
    2. getDay()
    3. getDayOfMonth()
    4. getDateOfMonth()
  23. To convert an object to JSON string, we may use which method?
    1. JSON.stringify(obj)
    2. JSON.toString(obj)
    3. JSON.parse(obj)
    4. JSON.toJSONString(obj)

True or False Question

  1. String is immutable, which means cannot be changed after it is created.
  2. Array is one kind of special object in JavaScript.
  3. The index of array which has n elements starts from 0, ends with n - 1.
  4. In JavaScript, an array is static, which means it cannot add or remove a new element anytime.
  5. For...of loop can be used to iterate over array.
  6. We can use the same way to access one character of a string with the array.
  7. In Javascript, the escape characters are used to represent special characters which cannot be directly used in the string.
  8. Map, Set and Array are all the objects in JavaScript.

Definition of Term

  1. Array
  2. JSON
  3. Regular Expression
  4. Escape Characters

Short Answer

  1. Try to compare with the for...of and for...in loops.
  2. Try to explain ways to express a string.
  3. What are the differences between the Map and Set?

Programming

  1. Write a function to find the maximum number in an array.
  2. Write a function to reverse an array.
  3. Write a function to check whether a string is palindrome(for example: "abcdcba" is palindrome) or not.
  4. Write a function to generate an array to store the length for each word in a sentence, which contains only letters and spaces.
  5. Write a function to find the longest word in a sentence.
  6. Write a function to calculate the days between two dates.
                    
                        function getDays(date1, date2) {
                            // your code here
                        }
                        alert(getDays(new Date(2014, 0, 3), new Date(2014, 0, 1)));
                    
                
  7. Write code to display the current time on the web page.
  8. Write functions to generate a random color, such as '#44235d'.
  9. Write code to output the maximum days for each month according to the year and month input by the user, you need consider the leap year.
  10. Write a function to check whether a phone number is valid or not. The rules: 1)start with 1-9; 2)length is 11; 3)the first digit is 1 or 8 or 9
  11. Write a function to sort an array of strings by the length.