Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ? mean in Angular function arguments?

While going through an Angular 4 tutorial I found a new way of getting/setting parameter in function.

onValueChange(data?: any)

What does the ? do?

like image 597
Rakhi Prajapati Avatar asked Jun 18 '26 02:06

Rakhi Prajapati


1 Answers

? sign denotes optional. Meaning that if you don't pass the value to function, it won't throw an error.

For example:

This is your function

onValueChange(data?: any) {
  console.log(data);
}
onValueChange('somedata'); // will print 'somedata' in the console
onValueChange(); // will print undefined but it won't throw an error

Summary: You can call this function without passing the value as it is optional.

like image 200
Surjeet Bhadauriya Avatar answered Jun 21 '26 00:06

Surjeet Bhadauriya