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

SEARCH KEYWORD -- private variable



  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

  strange thing in PHP session variable and local variable

A few minutes ago, I noticed one strange thing when I did my PHP web application development.The situation is described below:I want to display a user's profile using a query parameter user=user_id as the parameter. And also the session variable when user logs in  is $_SESSION["user"].So before displaying the user's profile, I need to either get the query string parameter user and create a local variable called $user and assign value to it as $user=$_REQUEST["user"].Here comes the strange t...

   PHP,session,variable name,change automat     2011-06-13 12:23:59

  Why can System.out.println be used to exit while loop

Let's first take a look at one simple Java thread code snippet which is supposed to exit the while loop after the first loop run. public class StopThread { private static boolean stopRequested; public static void main(String[] args) throws InterruptedException { Thread backgroundThread = new Thread(new Runnable() { @Override public void run() { int i = 0; while (!stopRequested) { i++; } } }); backgroundThread.start(); TimeUnit.SECONDS.sleep(1); stopRequested = true; } } But the tr...

   JAVA,THREAD,VOLATILE     2018-12-21 19:25:54

  Sort an array with only one local variable

Array sorting algorithm question is frequently asked during technical interviews. There are lots of sort algorithms including bubble sort, selection sort, insertion sort, quick sort, merge sort etc. Usually interviewees will be asked to implement sort algorithms. But have you ever been asked to sort an array which you are allowed to define ONLY ONE local variable in your algorithm?  Bubble sort can be used to do this actually. Normally a bubble sort algorithm may need three local ...

   JAVASCRIPT,ALGORITHM,SORTING,BUBBLE SORT     2016-10-07 09:46:49

  Name resolution order in JavaScript

To understand what value a variable has in JavaScript, we need to understand some concepts such as scope and name resolution order. JavaScript has two scopes; one is program level and the other one is function level. Unlike in C,C++ or Java, JavaScript has no block level scope. So a variable defined in a if block will still be available outside. For example, the below example: var foo = 1; function bar() { if (true) { var foo = 10; } alert(foo); } bar(); The alert will display 10 since the ...

   JavaScript,Scope,Name resolution     2013-07-10 01:29:28

  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

  this in JavaScript in detail

this in JavaScript is always confusing, it is one of the most frequently seen traps in JavaScript. this is not a good design in JavaScript(You can refer some other design flaws of JavaScript here), since it's lazy binding feature, it can be a global object, the current object or.... Some people even avoid using this in JavaScript. Actually if you master how this works, then you will know how to stay away from these traps. Let's take a look at what this points to in below situations. 1. In global...

   JavaScript,this,bind     2013-05-09 18:35:12

  Three ways to define class in JavaScript

In object oriented programming, class is the template of object, it defines the properties and methods of a group of objects. Unfortunately, JavaScript doesn't support class, but we can have some workarounds to simulate class.1. Constructor functionThis is the classical approach, it is also the approach mentioned in many text books. It uses the constructor function to simulate class and it uses the keyword this to represent the object internally.function Cat() {  this.name = "Kelly...

   JavaScript,Class,Method,Private,Inheritance     2012-07-09 11:59:51

  Public Vs. Private Cryptocurrency Keys

Before investing in any form of cryptocurrency, you must become familiar with the terminology used in the industry. This will prevent mistakes that could jeopardize your entire investment, and no one should be investing in any type of security or asset that they don't fully understand first. Crypto Wallets Before we even delve into what public and private keys are, we first need to discuss what the keys are for. Your Bitcoin or crypto wallet is basically the account that you store your cryptocur...

   SECURITY,CRYPTOCURRENCY     2022-03-06 08:17:30

  How many bytes a boolean value takes in Java?

Have you ever wondered how many bytes a boolean value takes in Java? One byte, this might be the answer comes out of your mind right away. But is it? Let's dig in more. Per Oracle documentation on boolean value definition, there is below statement: boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defin...

   JAVA,INTERVIEW,SIZE,BOOLEAN     2020-02-29 02:49:18