How to call Typescript function from JavaScript ? Last Updated : 22 Mar, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we will try to understand all the facts which are associated with how we may call typescript function from JavaScript. TypeScript supports the existing JavaScript function syntax for declaring and calling it within the program or the code snippet. Let us quickly understand how we may declare a function in TypeScript. Syntax for declaring TypeScript Function: Following syntax we may use to declare any function in TypeScript- function function_name (parameter_name : data_type, ...) : return_type { // Do something..... } Now that we have seen the syntax of declaring a typescript function let us quickly jump into the part of the following example where we will see how we call the typescript functions, which we are going to declare in a while, using the similar manner as we do by following a certain syntax in JavaScript- Example 1: In this example, we will simply implement a function that will print the sum of two numbers upon calling. This is the simplest example we are taking into account in the beginning. Moreover, we will be using the arrow function in this example itself. JavaScript let sumOfNumbers = ( firstnum : number, secondnum : number ) : number => { return firstnum + secondnum; } console.log(sumOfNumbers(4 , 5)); console.log(sumOfNumbers(15 , 19)); Output: 9 34 Example 2: In this example, we will try to implement a typescript function that will accept its data from the statically typed object (a feature provided by TypeScript wherein we may declare an object using type before the name of the object), and thereafter we will use the data to actually print the data of a user. JavaScript type userDetails= { firstName: string; lastName: string; }; let displayUserName = (userDetail : userDetails) => { return "Name of the user is : " + `${userDetail.firstName} ${userDetail.lastName}`; } let user : userDetails= { firstName: "ABC", lastName: "DEF" }; let userName = displayUserName(user); console.log(userName); Output: Name of the user is : ABCDEF Comment More infoAdvertise with us Next Article How to call Typescript function from JavaScript ? A amansingla Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League TypeScript Geeks-Premier-League-2022 JavaScript-Questions +1 More Similar Reads How to Call a JavaScript Function from an onsubmit Event ? The onsubmit event attribute in HTML is triggered when a form is submitted. It is also useful for validating form data or performing actions before any submission and ensures better control and validation of user inputs before data is sent. The below methods can be used to call a JavaScript function 2 min read How to Call a JavaScript Function from Chrome Console ? One can call a JavaScript Function from the Chrome Console. We will learn how can we call the function in the console that is written in JavaScript. Steps to call a JavaScript Function from Chrome ConsoleOpen the Chrome ConsoleYou can open the Chrome Console by right-clicking on your webpage, select 2 min read How to call JavaScript function in HTML ? In HTML, you can easily call JavaScript functions using event attributes like onclick and onload. Just reference the function name within these attributes to trigger it. You can also call functions directly within script blocks using standard JavaScript syntax. Let's create an HTML structure with so 2 min read How to write a function in Typescript ? Writing a function in TypeScript is similar to writing it in JavaScript but with added parameters and return type. Note that any JavaScript function is a perfectly valid TypeScript function. However, we can do better by adding type.Syntax: Let's see a basic TypeScript function syntax (with two argum 4 min read How to call function from it name stored in a string using JavaScript ? In this article, we will call a function from the string stored in a variable. There are two methods to call a function from a string stored in a variable. Using window object methodUsing eval() method Note: The eval() method is older and is deprecated. Method 1: Using the window object. The window 2 min read Like