Posts

Showing posts from June, 2020

Dealing with numbers in javascript

Numbers in JavaScript the Basics JavaScript has just  one  number type. i.e 5  and  5.10  are the same type. JS uses the “ double-precision 64-bit format IEEE 754 ” standard What does this mean? All JavaScript numbers are stored as  double floating point numbers . JS will trick you into thinking that your const  x = 5  is an integer, but really it’s a float and equal to x = 5.0 test youself !!! 5 == 5.0 true Math Object JavaScript has a built-in Math object that provides a range of mathematical methods and properties. The most useful methods are: Math.ceil : rounds a number upwards, so  Math.ceil(8.23)  returns 9 Math.floor : rounds a number downwards, so  Math.floor(23.8)  returns 23 Math.round : rounds the number to the nearest integer, so  Math.round(8.3)  returns 8, while Math.round(2.8) returns 3 Math.pow : raises one number to the power of another so  Math.pow(2,3)  returns Testyourself: Math.ceil(28....

Tightcoupling what ???

Tight coupling (in general) is when two things depends on one another, that is, changing one may have impact on another. In JavaScript, method and object is said to be tightly coupled. Suppose you change  person.name  to  person.naame , the method  sayName()  will break, so are other methods that access name using this way. One way to slightly loose the coupling is to provide a getter method  getName()  and use it instead of referencing the instance variable directly. Hence if you want to change  person.name  to something else, you just need to change this method. Tight coupling using the above explanation would be like this : var person = { name : " Jack " , sayName : function () { alert ( person . name ) ; } };     

Working of static content Vs dynamic content

Image
What is the difference between static and dynamic content? Static content is any file that is stored in a server and is the same every time it is delivered to users. HTML files and images are examples of this kind of content. Static content is like a newspaper: once an issue of a newspaper is published, it features the same articles and photos all day for everyone who picks up a copy, no matter what new developments transpire during the day. Dynamic content is content that changes based on factors specific to the user such as time of visit, location, and device. A dynamic webpage will not look the same for everybody, and it can change as users interact with it – like if a newspaper could rewrite itself as someone is reading it. This makes webpages more personalized and more interactive. A modern news website is a good example of dynamic content: unlike in a newspaper, articles are updated throughout the day, and the homepage may feature different headlines based on the site visitor...

How to work with Date and time in Javascript ??

A JavaScript date is fundamentally specified as the number of milliseconds that have elapsed since midnight on January 1, 1970, UTC. This date and time is the same as the  UNIX epoch.                               Date Format and timezone conversion:      " There are a number of methods available to obtain a date in various formats, as well as to perform time zone conversions. Particularly useful are the functions that output the date and time in Coordinated Universal Time (UTC), the global standard time defined by the World Time Standard. (This time is historically known as  Greenwich Mean Time ,"                                   DATE OBJECT  The  Date   object  is a built-in object in JavaScript that stores the date and time. It provides a number of built-in methods for format...

EVENT_DRIVEN CONCEPTS

Image
        " Learn my section Asynchronous before moving to this" JavaScript is an e vent-driven programming language which inherently supports non-blocking operations. Using JavaScript you can register code to specific events and that code will be executed once the event is emitted, enabling the seamless execution of asynchronous code without blocking other operations. < h1 > If you love JavaScript < /h1> Enter your name ? < input id = "nameInput" type = "text" /> < input id = "showNameButton" type = "button" value = "Submit" /> < script type = "text/javascript" > var showNameButton = document . getElementById ( 'showNameButton' ); showNameButton . addEventListener ( 'click' , function () { alert ( document . getElementById ( 'nameInput' ). value + ' loves JavaScript!' ); }); < /script> As simple as this example is, it illustrates...