Monday 12 November 2012

HMTL 5, CSS3 and JavaScript for Windows 8 – Little JavaScript tips

In this post I am going to add these small things I always forget when I work with JavaScript and are quite useful:

  1. How do you put a message in the browser’s status bar?: windows.status(“hello world”);
  2. What do you use to comment in JavaScript?: // and /* */
  3. What is the correct way to write a JavaScript array?: var txt = new Array (“Hello”,”World”, “how”);
  4. How do you write something with JavaScript?: document.write(“Hello World”);
  5. How does a “while” loop start?: while(i<=10);
  6. What is the purpose of DOM (Document Object Model)?: The DOM represents the structure of a web page. You use it to add dynamic functionality to the page.
  7. DOM core methods to create new objects for a document:
      • document.createElement(tagname)
      • document.createTextNode(string)
      • document.createAttribute(name,value)
      • document.createDocumentFragment
  8. How do you round a number to the nearest integer?: Math.round(7.25);
  9. How do you find the Maximum number between two numbers?: Math.max(x,y);
  10. How to pass a JavaScript reference into a website: <script type=”text/javascript” src=”alertme.js”></script>
  11. Internet Explorer 6,7 and 8 do not support addEventListener() and removeEventListener(). Use similar attachEvent() and detachEvent() functions instead.
    Some events in the HTML DOM ‘bubble’ meaning that if the event occurs on an element (and it is or isn’t handled), the event will then also fire on the element’s parent node and then on its grandparent node and so on until the event reaches an element where it may not bubble any further or it reaches the root node. Both addEventListener and removeEventListener have an optional third Boolean parameter indicating whether or not this is the case.
  12. How do you find clients browser name?: navigator.appName
  13. How do you open a new window in JavaScript?:mywindow=window.open(“http://www.google.com”);
  14. How do you split a large string in two lines in Javascript?:
    document.write(“hello my name is \
    prince”);
  15. Microsoft implementation of JavaScript is called JScript.
  16. <noscript> tag Alerts the users that your page uses JavaScript, and so the user should enable JavaScript in the browser in order to display your page correctly.
  17. Having the following code what does this code returns….(this is a nice exercise):

<script>
var a=””
var b=0;
var c=false;
document.write(a==c);//true
document.write(a===c);//false
document.write(b==c);//true
document.write(b===c);//false
</script>



</script>

No comments: