JS Quiz Exercise Lab

 

JS Quiz Exercise Lab

Front End Developers-Lab


(JS) JavaScript
Interview Questions and Anwsers

Practice Before Interview or Quiz

(JS) JavaScript is the programming language that runs in the browser, which is used to build advanced interactive Web sites and applications for secure browser execution.


      JS Quiz Exercise Lab

      What is Javascript?

      JavaScript is the scripting language of the Web.JavaScript is used in millions of Web pages to add functionality, validate forms, detect browsers, and much more.


      What Javascript can do?

      What Javascript can do? As: JavaScript gives HTML designers a programming tool JavaScript can put dynamic text into an HTML page JavaScript can react to events JavaScript can read and write HTML elements.
      - JavaScript can be used to validate data
      - JavaScript can be used to detect the visitor's browser
      - JavaScript can be used to create cookies

      What is a Javascript statement?

      A JavaScript statement is a command to a browser. The purpose of the command is to tell the browser what to do.

      What is the difference between XML and HTML?

      XML is not a replacement for HTML. XML and HTML were designed with different goals:
      1- XML was designed to transport and store data, with focus on what data is.
      2- HTML was designed to display data, with focus on how data looks.
      The difference is
      HTML is about displaying information, while XML is about carrying information.

      What is a javascript object?

      A collection of data containing both properties and methods. Each element in a document is an object. Using the DOM you can get at each of these elements/objects and do some cool sh*t.

      Describe what event bubbling is?

      Event bubbling causes all events in the child nodes to be automatically passed to its parent nodes. The benefit of this method is speed because the code only needs to traverse the DOM tree once.

      Describe what "this" is in JavaScript?

      In JavaScript, 'this' normally refers to the object which 'owns' the method, but it depends on how a function is called.

      What is the difference between == and === ?

      The 3 equal signs mean "equality without type coercion". Using the triple equals, the values must be equal in type as well.

      == is equal to
      === is exactly equal to (value and type)
      0==false // true
      0===false // false, because they are of a different type
      1=="1" // true, auto type coercion
      1==="1" // false, because they are of a different type
      Resources for this answer:

      Where do you place your JavaScript on the page?

      It may depend on what you are using it for. There is some debate on this but generally a good question to ask to get an understanding of the JS knowledge. Answers:

      What is a closure?

      Closures are expressions, usually functions, which can work with variables set within a certain context. Or, to try and make it easier, inner functions referring to local variables of its outer function create closures. Resources for this answer:

      What is Global Namespacing?


                 
      
      "1" + 2 + "3" + 4;
      

      What does the above statement evaluate to?

      • 10
      • 1234
      • 37

      1234


      4 + 3 + 2 + "1"
      

      What does the above statement evaluate to?

      • 10
      • 4321
      • 91

      91


      var foo = 1;
      function bar() {
      	foo = 10;
      	return;
      	function foo() {}
      }
      bar();
      alert(foo);
      

      What is alerted?

      • 1
      • 10
      • Function
      • undefined
      • Error

      1


      function bar() {
          return foo;
          foo = 10;
          function foo() {}
          var foo = 11;
      }
      alert(typeof bar());
      

      What is alerted?

      • number
      • function
      • undefined
      • Error

      Function


      var x = 3;
      
      var foo = {
          x: 2,
          baz: {
              x: 1,
              bar: function() {
                  return this.x;
              }
          }
      }
      
      var go = foo.baz.bar;
      
      alert(go());
      alert(foo.baz.bar());
      

      What is the order of values alerted?

      • 1, 2
      • 1, 3
      • 2, 1
      • 2, 3
      • 3, 1
      • 3, 2

      3, 1


      var x   = 4,
          obj = {
              x: 3,
              bar: function() {
                  var x = 2;
                  setTimeout(function() {
                      var x = 1;
                      alert(this.x);
                  }, 1000);
              }
          };
      obj.bar();
      

      What value is alerted?

      • 1
      • 2
      • 3
      • 4
      • undefined

      4


      x = 1;
      function bar() {
          this.x = 2;
          return x;
      }
      var foo = new bar();
      alert(foo.x);
      

      What value is alerted?

      • 1
      • 2
      • undefined

      2


      function foo(a) {
          alert(arguments.length);
      }
      foo(1, 2, 3);
      

      What value is alerted?

      • 1
      • 2
      • 3
      • undefined

      3


      var foo = function bar() {}; 
      alert(typeof bar);
      

      What value is alerted?

      • function
      • object
      • undefined

      undefined


      var arr = [];
      arr[0]  = 'a';
      arr[1]  = 'b';
      arr.foo = 'c';
      alert(arr.length);
      

      What value is alerted?

      • 1
      • 2
      • 3
      • undefined

      2


      function foo(a) {
          arguments[0] = 2;
          alert(a);
      }
      foo(1);
      

      What value is alerted?

      • 1
      • 2
      • undefined

      2


      function foo(){}
      delete foo.length;
      alert(typeof foo.length);
      

      What value is alerted?

      • number
      • undefined
      • object
      • Error

      Number


      var foo = function foo() {
          console.log(foo === foo);  
      };
      foo();
      

      What is printed in the console?

      • true
      • false
      • ReferenceError

      true


      function aaa() {
          return
          {
              test: 1
          };
      }
      alert(typeof aaa());
      

      What does the above alert?

      • function
      • number
      • object
      • undefined

      undefined


      Number("1") - 1 == 0;
      

      What is the result?

      • true
      • false
      • TypeError

      true


      (true + false) > 2 + true;
      

      What is the result?

      • true
      • false
      • TypeError
      • NaN

      false


      function bar() {
          return foo;
          foo = 10;
          function foo() {}
          var foo = '11';
      }
      alert(typeof bar());
      

      What is alerted?

      • number
      • function
      • undefined
      • string
      • Error

      function


      "1" - - "1";
      

      What is the result?

      • 0
      • 2
      • 11
      • "11"

      2


      var x = 3;
      
      var foo = {
          x: 2,
          baz: {
              x: 1,
              bar: function() {
                  return this.x;
              }
          }
      }
      
      var go = foo.baz.bar;
      
      alert(go());
      alert(foo.baz.bar());
      

      What is the order of values alerted?

      • 1, 2
      • 1, 3
      • 2, 1
      • 2, 3
      • 3, 1
      • 3, 2

      3, 1


      new String("This is a string") instanceof String;
      

      What is the result?

      • true
      • false
      • TypeError

      true


      [] + [] + 'foo'.split('');
      

      What is the result?

      • "f, o, o"
      • TypeError
      • ["f", "o", "o"]
      • [][]["f", "o", "o"]

      "f, o, o"


      new Array(5).toString();
      

      What is the result?

      • ",,,,"
      • []
      • "[]"

      ",,,,"


      var myArr = ['foo', 'bar', 'baz'];
      myArr.length = 0;
      myArr.push('bin');
      console.log(myArr);
      

      What is printed in the console?

      • ['foo', 'bar', 'baz']
      • ['foo', 'bar', 'baz', 'bin']
      • ['bin', 'foo', 'bar', 'baz']
      • ['bin']

      ['bin']


      String('Hello') === 'Hello';
      

      What is the result?

      • true
      • false
      • TypeError

      true


      var x = 0;
      function foo() {
          x++;
          this.x = x;
          return foo;
      }
      var bar = new new foo;
      console.log(bar.x);
      

      What is printed on the console?

      • ReferrenceError
      • TypeError
      • undefined
      • 0
      • 1

      undefined


      "This is a string" instanceof String;
      

      What is the result?

      • true
      • false
      • TypeError

      false


      var bar = 1,
          foo = {};
      
      foo: {
          bar: 2;
          baz: ++bar;
      };
      foo.baz + foo.bar + bar;
      

      What is the result?

      • ReferenceError
      • TypeError
      • undefined
      • NaN
      • 4
      • 5

      NaN


      var myArr = ['foo', 'bar', 'baz'];
      myArr[2];
      console.log('2' in myArr);
      

      What is the result of console.log?

      • true
      • false
      • ReferenceError

      true


      var arr = [];
      arr[0]  = 'a';
      arr[1]  = 'b';
      arr.foo = 'c';
      alert(arr.length);
      

      What value is alerted?

      • 1
      • 2
      • 3
      • undefined

      2


      10 > 9 > 8 === true;
      

      What is the result?

      • true
      • false

      false


      function foo(a, b) {
          arguments[1] = 2;
          alert(b);
      }
      foo(1);
      

      What value is alerted?

      • 2
      • undefined
      • ReferenceError

      undefined


      NaN === NaN;
      

      What is the result?

      • true
      • false
      • TypeError

      false


      What type of object system does JavaScript support?

      Resources for this answer: $(document).ready(function(){ $('.loader img').click(function() { $('.loader img').hide(); \\ $('.loader img').hide(); }); });

      Are you sure you're ready for this Quiz ?

      JavaScript Web Quiz By David Shariff

        The Benefits of Front-End