Erstellt von James Drummond
vor fast 10 Jahre
|
||
Frage | Antworten |
What does 'new' do in Javascript? | 1. A new object is created, inheriting from parent.prototype. 2. The Constructor function is called with the specified arguments and this bound to the newly created object 3. The object returned by the constructor function becomes the result of the whole new expression. If the constructor function doesn't explicitly return an object, the object created in step 1 is used instead. |
What is hoisting in Javascript? | All of the declarations are hoisted to the top of the scope |
When you declare a variable and assign a value and it's hoisted, is the value hoisted with the declaration? | No. Only the declaration is hoisted. |
What are the five 'falsey' values in Javascript? | undefined, null, NaN, 0, '', false |
What are some features of Ecmascript 6? | - Maps, sets and associated functions - Templates - Modules, classes - Make inheritance simpler |
How do you test if something is an array? | - IE9+ : isArray() - If variable.constructor === Array - If variable instanceof Array |
What are the four types of function invocation in Javascript? | - method invocation: obj.method(); - function invocation: method(); - constructor invocation: new Obj(); - call(), apply() |
What is a closure | An 'immediate' or 'self invoking' function whose private variables retain their value after the function has returned. |
What are the datatypes in Javascript? | String Number Boolean Object Array |
What is the quickest way of finding an element in an array? | .indexOf() - Uses strict equality - Not supported by all browsers |
How do you compare objects for equality in Javascript? | - You can JSON.stringify the objects and compare the strings _.isEqual() - angular.equals(o1, o2) |
What is a polyfill? | Code or plugin that enables you to use un-supported functions natively |
What is the purpose of Object.create()? | - Use it to instantiate a subclass. - Takes prototype as argument - Usually assign the result to the prototype of the subclass |
What are some built in methods of Object? | - toString() - isPrototypeOf() - hasOwnMethod() - hasOwnProperty() - constructor |
Why would you use hasOwnProperty()? | If you were iterating the properties of an object: for(var prop in obj){ if (obj.hasOwnProperty(prop){ // property not on prototypal chain } } - could make sure this object had the specific property |
What are some built in methods of Array? | - pop() - push() - reverse() - toString() - join() - slice() - splice() - reverse() - sort() indexOf() |
What is typeof null? | object |
What is typeof NaN? | number |
What is typeof null? | Object |
What does 'use strict' do? | Enforces strict syntax: will not allow: - undeclared variables - redeclaration of variables |
What are some bad things about Javascript? | - implied globals - No inbuilt modularity - forgetting 'new' keyword |
How do you determine if an object is a prototype of another object? | newObject.isPrototypeOf(oldObject) |
How do you add two arrays together in Javascript? | var newArray = array1.concat(array2) |
How would you create a subclass in javascript with Object.create()? | function Rectangle() Rectangle.prototype = Object.create(Shape.prototype) Rectangle.constructor = Shape.constructor |
How do you create a subclass using new? | function Child(arg1, arg1){ Parent.apply(this, args); }; Child.prototype = new Parent() |
What is the constructor property in Javascript? | It's a reference to the Constructor function. Practically it is not used for very much |
How do you insert a character into a string in Javascript? | Remember that Javascript strings are immutable var myStr = 'hi there'; var newString = myStr.subStr(0, i) + 'u' + myStr.subStr(i + 1); |
How do you remove an item from the beginning of an array? | var fruits = ["Apple", "Banana"]; fruits.shift(); |
How do you add an item to the beginning of an array? | fruits.unshift() |
How do you find the index of an item in an array? | var fruits = ["Apple", "Banana", "mango"]; var index = fruits.indexOf('mango'); |
How do you remove an item from an array? | var pos = 1; var removedItem = fruits.splice(pos, 1); // Remove one item from position one |
Möchten Sie mit GoConqr kostenlos Ihre eigenen Karteikarten erstellen? Mehr erfahren.