DEV Community

Cover image for Best practices problems on Javascript Variable.
Devendra Devendra
Devendra Devendra

Posted on

Best practices problems on Javascript Variable.

1.Write a javascript programm to switch two interger values.
var n1=20
var n2=30
Output:
n1=30
n2=20

2.Wap to switch two interger values without using extra variables.
var n1=20
var n2=30
Output:
n1=30
n2=20

3.Write a programm to switch two character values.
var char1="hello"
var char2="javascript"
Output:
char1="javascript"
char2="hello"

4.Write a programm to switch one character to one interger values.
var n1=200
var char2="javascript"
Output:
n1="javascript"
char2=200

5.Write a programm to switch two character values.
var char1="hello"
var char2="javascript"
Output:
char1="javascript"
char2="hello"

6.Write a programm to update balance of a customer .
var current_balance=10000
var deposit_balance=5000
Output:
before deposite:current_balance=10000
after deposite:current_balance=15000

7.Write a programm to update full name of a customer .
var full_name=""
var first_name="hello"
var last_name="javascript"
Output:
before update:full_name=""
after update:full_name="hello javascript"

8.Write a programm to update balance of a customer .
var current_balance=10000
var withdraw_balance=2000
Output:
before withdraw:current_balance=10000
after withdraw:current_balance=8000

9.Write a programm to calculate percentage of a student marks
430 out of 500 each subject hold 100marks and total suject is 5.

var obtain_marks=430
var out_of=500
Output:
Pecentage = ?

JavaScript variables play a pivotal role in shaping the structure and behavior of code. Adopting best practices, understanding scoping rules, and choosing appropriate variable names contribute to the development of robust, readable, and efficient JavaScript programs.

KEEP GRINDING , NEXT TURORIAL COMMING SOON πŸ”₯

Top comments (0)