function test(){
if(this === null){
console.log("This is null");
}else{
console.log("This is Object");
}
}
test.call(null);
test.call({});
Output :
This is Object.
This is Object.
But I expect Output :
This is Null.
This is Object.
Why Null not set in context ?
ISBLANK is the function for NULL. use ISBLANK to check NULL. Your expression will be like below, Please check in editor for accuracy. 04-08-2020 09:28 PM It's not quite correct though because if they use the blank in a calculation it will count as 0 not NULL.
This program looks as though it is ought to throw a NullPointerException. However, the main method invokes the greet method (fun) on the constant null, and you can’t invoke a method on null. But, when you run the program, it prints “Welcome to GeeksforGeeks!!”.
ISBLANK is the function for NULL. use ISBLANK to check NULL. Your expression will be like below, Please check in editor for accuracy. 04-08-2020 09:28 PM It's not quite correct though because if they use the blank in a calculation it will count as 0 not NULL. Which will introduce errors. 07-03-2018 05:51 AM Blank () is working in Dax.
You reference a context variable in a formula by using the variable's column name. For example, UpdateContext ( { ShowLogo: true } ) creates a context variable named ShowLogo and sets its value to true. You can then use the value of this context variable by using the name ShowLogo in a formula.
Quoting from MDN
if the method is a function in non-strict mode,
null
andundefined
will be replaced with the global object and primitive values will be converted to objects.
This explains why you get an object when you call test.call(null);
. When null
is passed here, this
inside test()
will be global object Window
.
For the desired behavior, use strict mode.
function test() {
"use strict";
if (this === null) {
console.log("This is null");
} else {
console.log("This is Object");
}
}
test.call(null);
test.call({});
Quoting from ES6 Specifications for strict mode
If
this
is evaluated within strict mode code, then thethis
value is not coerced to an object. Athis
value ofnull
orundefined
is not converted to the global object and primitive values are not converted to wrapper objects. Thethis
value passed via a function call (including calls made usingFunction.prototype.apply
andFunction.prototype.call
) do not coerce the passed this value to an object
What does the 'this' indicate? you can use console.log(this);
to know it. But as answer, use an input (here I called it input
) and test it.
function test(input){
if(input=== null){
console.log("This is null");
}else{
console.log("This is Object");
}
}
test(null);
test({});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With