---
title: "How to get javascript variable's value in iOS app?"  
description: "How to get javascript variable's value in iOS app?"  
author: "Anonymous User"  
published: 2014-11-12  
updated: 2014-11-12  
canonical: https://www.mindstick.com/forum/12564/how-to-get-javascript-variable-s-value-in-ios-app  
category: "iphone"  
tags: ["javascript", "ios", "objective c"]  
reading_time: 1 minute  

---

# How to get javascript variable's value in iOS app?

I need to [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) a [javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) which is declared inside a try [block](https://www.mindstick.com/forum/157599/explain-the-process-control-block-pcb-in-the-operating-system) in the [script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line)

var ErrorResponse = "";

in my [iOS app](https://www.mindstick.com/forum/160260/what-is-the-best-place-to-hire-an-ios-app-developer). I don't have much idea about javascript thats why I [am unable](https://answers.mindstick.com/qa/95314/how-do-i-access-a-group-link-in-telegram-if-i-am-unable-to-access-the-link) to find out the way to do it. I am using this:

NSString *jsString = @"var temp = ErrorResponse; return temp";

NSString *myFieldValue1 = [self.viewYTParser stringByEvaluatingJavaScriptFromString:jsString];

to [retrieve](https://www.mindstick.com/forum/34400/how-to-retrieve-form-values-in-controller-action) the [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) but it returns an [empty string](https://www.mindstick.com/forum/12697/json-stringify-is-sending-empty-string).

## Replies

### Reply by Elena Glibart

**Here is the code that should do the magic:**

```
NSString *errorResponse = [self.viewYTParser
stringByEvaluatingJavaScriptFromString:@"ErrorResponse"];
```

Just execute this line each time you need to retrieve the up-to-date value of ErrorResponse.

**You shouldn't use the return keyword.**\
If you want your JS to return any value from stringByEvaluatingJavaScriptFromString then it should be something that you would regularly write **after** the return keyword in regular JS function - without the return word itself.


---

Original Source: https://www.mindstick.com/forum/12564/how-to-get-javascript-variable-s-value-in-ios-app

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
