File tree Expand file tree Collapse file tree
JavaScript Interview Programs Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- const a = 10 ;
2- const b = 20 ;
3- const c = a + b ;
4- console . log ( c )
1+ // Common Ways to Add Numbers In JavaScript
2+
3+ // 1. Normal Variable Addition (Direct Way)
4+ const a = 10 ;
5+ const b = 20 ;
6+ const sum = a + b ;
7+ console . log ( "Addition of two number" : sum ) ;
8+ // output:
9+ // Addition of two number: 30
10+
11+ // 2. One-Line Addition (Used for Console testing or demo purpose)
12+ Console . log ( 10 + 5 ) ;
13+ // Output:
14+ // 15
15+
16+ // 3. Using "prompt()" It take Inputs from User, Convert to number and Perform Addition – Runs only in browser
17+ let a = Number ( prompt ( "Enter first number:" ) ) ;
18+ let b = Number ( prompt ( "Enter second number:" ) ) ;
19+ console . log ( "Sum:" , a + b ) ;
20+ // Output:
21+ // Enter frist number: 2
22+ // Enter second number: 8
23+ // Sum: 10
You can’t perform that action at this time.
0 commit comments