Today's Question:  What does your personal desk look like?        GIVE A SHOUT

SEARCH KEYWORD -- JAVASCRIPT



  A small trick on using console.log to print data in JavaScript

When debugging JavaScript application, one may frequently use console.log to print data so that it is easy to debug when issue occurs and also helps on understand the data flow. The common way of printing a variable would be something like.  let user = { name: "test" }; console.log(user); In this case it will print: { name: 'test' } This is OK when there is no much logging or the program is not complicated. But it becomes difficult to debug if there are lots of variables to be printed ...

   JAVASCRIPT,CONSOLE.LOG,DEBUGGING     2019-09-03 10:24:24

  Google open sources Leak Finder for JavaScript

Google recently open sourced a tools for finding memory leaks in JavaScript programs. In JavaScript you cannot have "memory leaks" in the traditional sense, but you can have objects which are unintentionally kept alive and which in turn keep alive other objects, e.g., large parts of DOM. Leak Finder for JavaScript works against the Developer tools remote inspecting protocol of Chrome, retrieves heap snapshots, and detects objects which are "memory leaks" according to a given leak definition. The...

   Google,Open source,JavaScript     2012-08-15 13:45:34

  JavaScript JVM runs Java

The world of software is made slightly crazy because of the huge flexibility within any computer language. Once you have absorbed the idea of a compiler written in the language it compiles what else is there left to gawp at? But... a Java Virtual Machine JVM written in JavaScript seems like another level of insanity.In fact it is a quite reasonable idea which is only made mad by the usual positions that Java, the top dog, and JavaScript the underling, usually occupy. Java is compiled not to mach...

   JavaScript,JVM,BicaVM,Cross platform,JavaScript written JVM     2011-11-22 02:51:38

  You can get properties of pseudo-element using JavaScript now

The pseudo-element6 in CSS is extremely useful, you can use it to create CSS triangles and lots of other elements without overuse many HTML elements. In the past, you cannot get the property value of pseudo-element in CSS using JavaScript. Now you can call a new method in JavaScript to get them easily. Assume you have below CSS codes: .element:before { content: 'NEW'; color: rgb(255, 0, 0); } To get the properties in .element:before, you can use below JavaScript method: var color = window.getC...

   pseudo-element,property,JavaScript     2014-04-05 20:58:25

  Some short code snippets which use all JavaScript keywords

In JavaScript, keywords are reserved and cannot be used as variable or function names. For example void, function and this are JavaScript keywords, they are keywords which are reserved for special use. Here is list of the keywords in JavaScript. We also show you some short code snippets which use all the keywords in JavaScript.void function() {//abcd   do break;while(typeof delete this);  for(var a;;)  if (true)  with(null)  try{}catch(a){}finally{} else throw new 1;&nbs...

   Code snippet,JavaScript,keyword     2012-07-16 12:12:05

  Why 0.1+0.2 != 0.3

In programming languages such as JavaScript, c/c++, Java and Matlab, you will find that you will get unexpected result when doing float point calculation. For example, when calculating 0.1 + 0.1, you will not get 0.3: > 0.1 + 0.2 == 0.3 false > 0.1 + 0.2 0.30000000000000004 Don't be surprised of this result, this is the end result of IEEE 754 standard, float point number cannot be accurately represented according to IEEE 754 because: No enough memory is allocated for representing the num...

   float point,comparison,JavaScript     2014-11-19 05:32:46

  Which one has a worse reputation, JavaScript or PHP?

There has a been a lot of criticism of PHP over being a badly designed programming language. JavaScript seems quite a similar language with loose-typing and flexible array declarations/memory management, but is widely adopted by industry leaders such as Google. Google even has a JavaScript style guide. Many people think that PHP has a worse reputation than JavaScript. Carlos Ribeiro gave his analysis on a high level which doesn't touch the language syntax. Attributing JavaScript success to it be...

   JavaScript,PHP,reputation,comparison     2014-05-03 06:26:10

  Ways to check existence of JavaScript object

The design of JavaScript is not so sophisticated. It's very easy for us to make mistakes if we are not very careful when using JavaScript. For example, to check the existence of JavaScript object. Now we want to check whether a global object myObj exists or not, if it doesn't exist, we declare it. The pseudo code for this is : if(myObj not exist){ declare myObj; } You may think it's very easy to write the code. In fact, it is much more difficult than we may think. Juriy Zaytsev says there are m...

   JAVASCRIPT,OBJECT,EXISTENCE     2020-09-12 02:14:02

  Understanding an interesting JavaScript map function question

With the evolvement of JavaScript, lots of new features have been added this old but robust language.  Among them are lots of functional programming language related functions like map, filter, each etc. In this post, we will cover one function map and its interesting behavior. Before dive into the details, let first take an example, do you know the output of below function call? ['1', '7', '11'].map(parseInt) You may think that it's easy and the output would be [1, 7, 11] Can you try to ru...

   JAVASCRIPT,MAP,FUNCTIONAL PROGRAMMING     2019-06-14 08:34:46

  JavaScript: Private variables

The first thing you often hear when talking about JavaScript is often “JavaScript doesn’t have visibility modifiers, hence it doesn’t support private variables”. This is only valid for 50%, because JavaScript indeed doesn’t have visibility modifiers (public, private, friend) but it has closures and function scopes. With these tools we can make variables private. Let’s take the following function: var names = ["Kenneth", "John", "Marc", "Robert"]; var lookup =...

   JavaScript,private variable,closure     2012-04-28 11:46:34