xxxxxxxxxx
function greet(name: string, greeting: string = "Hello") {
console.log(`${greeting}, ${name}!`);
}
greet("John"); // Output: Hello, John!
greet("Sarah", "Hi"); // Output: Hi, Sarah!
xxxxxxxxxx
// Optional parameter
function foo(x?: number) {
console.log("x : "+ x);
}
foo();
foo(6);
xxxxxxxxxx
function multiply(a: number, b: number, c?: number): number {
if (typeof c !== undefined) {
return a * b * c;
}
return a * b;
}
xxxxxxxxxx
function greet(name: string = "Guest") {
console.log(`Hello, ${name}!`);
}
// Calling the function without providing an argument for 'name'
greet(); // Output: "Hello, Guest!"
// Calling the function with an argument for 'name'
greet("John"); // Output: "Hello, John!"
xxxxxxxxxx
/*
**DESCRIPTION**
Default-initialized parameters that come after all required
parameters are treated as optional, and just like
optional parameters, can be omitted when calling their
respective function
*/
export class Test {
constructor(private foo: string = "foo", private bar: string = "bar") {}
}
xxxxxxxxxx
# credit to Stack Overflow user in the source link
# shell command or ! + command in ipython
jupyter nbconvert --to script [YOUR_NOTEBOOK].ipynb